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中文网其他相关文章!