Sub S()
a = [o2].Text
b = [o7].Text
na = Len(a)
nb = Len(b)
ReDim arr(1 To na)
ReDim brr(1 To nb)
For i = 1 To na
arr(i) = Val(Mid(a, i, 1))
Next
For i = 1 To nb
brr(i) = Val(Mid(b, i, 1))
Next
For i = 1 To 9
a = ""
b = ""
#For j = 1 To na
a = a & (arr(j) i) Mod 10
Next
For j = 1 To nb
b = b & (brr(j) i) Mod 10
Next
[o2].Offset(0, i) = a
[o7].Offset(0, i) = b
Next
End Sub
想找出c列的最後一行有資料的行的程式碼是:
i=Cells(Rows.Count, 3).End(xlUp).Row
Selection.AutoFill Destination:=Range("D5:D" & i &"")
完整程式碼是:
Sub jj()
Range("D5").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-2]=RC[-1],""y"",""0"")"
#i = Cells(Rows.Count, 3).End(xlUp).Row
Selection.AutoFill Destination:=Range("D5:D" & i & "")
End Sub
因為截圖不全,我這裡先假設資料區為A1:F9, 填滿區為H1:M9
程式碼如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim arr1(1 To 54), arr2(1 To 54)
Dim x, y, z As Integer
Dim b, c
Dim a As Variant
z = 1
x = 1
y = 1
c = 1
For x = 1 To 9
For y = 1 To 6
arr1(z) = Cells(x, y)
z = z 1
Next y
Next x
z = z - 1
For z = 1 To 54
a = arr1(z)
b = z
For x = 1 To 54
If a
a = arr1(x)
b = x
End If
Next x
arr2(c) = a
c = c 1
arr1(b) = 0
Next z
c = c - 1
For x = 1 To 9
For y = 8 To 13
Cells(x, y) = arr2(c)
c = c - 1
Next y
Next x
End Sub
#運行結果
如幫到你請點個採納,謝謝^_^
樓主:你好,對於你這個問題有個前提條件:
如果你的Excel版本是2003版,那你只能用系統預設的56色。用VBA程式碼實現的其他填充色會被轉換成和這56色最接近的一種。
如果你的Excel版本是2007及以上,那麼單元格填充色幾乎不受限制,你完全可以透過單元格填充的命令實現自訂顏色填充,支援RGB、HSL兩種模式,無需借助VBA。
如果使用VBA,程式碼如下:
Sub test() '將A1儲存格填滿為紅色,RGB(紅,綠,藍) ,紅、綠、藍取值在0~255,可設定不同值以獲得不同顏色。 Range("A1").Interior.Color = RGB(255, 0, 0) '填滿紅色 '如果想去掉填滿色,用這句 Range("A1").Interior.Pattern = xlnoeEnd Sub
以上是使用EXCEL VBA自動填入數據的詳細內容。更多資訊請關注PHP中文網其他相關文章!