使用VBA对指定的单元格赋值并填充颜色 ====================================================== 代码区域 ====================================================== Sub row应用() For Each rw In Rows("1:13") = Then rw.Interior.ColorIndex = rw.Value = End If Next End Sub 效果如下图:
单元格内设置了有效性,通过VBA怎么去复制呢?代码如下: Public Sub 复制单元格批注() Dim range1 As range Dim range2 As range '清除G列 Columns("G:G").Clear Set range1 = range("A1:A2") '指定要复制的单元格区域 Set range2 = range("D1") '指定要复制的位置(左上角单元格 range1.Copy range2.PasteS
Sub W() ' MsgBox "行数:" & Selection.Rows.Count Dim rows_count As Integer Dim rows_id As Integer Dim column_count As Integer column_count = Selection.Columns.Count '获取选择区域的列数 'MsgBox column_count '打印列数 rows_id = ActiveCell.
只复制单元格的批注该怎么操作呢?代码如下: Public Sub 复制单元格批注() Dim range1 As range Dim range2 As range '清除G列 Columns("G:G").Clear Set range1 = range("A1:B4") '指定要复制的单元格区域 Set range2 = range("G1") '指定要复制的位置(左上角单元格 range1.Copy range2.PasteSpecial
Sub 将所有列全部转换为文本() t=timer 'Cells(Rows.Count, 1).End(xlUp).Row 获取第一列最后一个非空单元格的行号 s = Cells(, Columns.Count).End(xlToLeft).Column '获取第一行最后一个非空单元格的列号 For i = To s Columns(i).Select Selection.TextToColumns Destination:=Cells(, i), DataType:=xlDelimited,
Then .Range("AF4").Value = pjno .Range("A1:AH56").Locked = False .Range("F6:M6").Locked = True ActiveSheet.Protect Password:="locked" Exit Sub Else .Range("AF4").Value = pjno End If
动态数组使用: https://zhidao.baidu.com/question/1432222709706721499.html 使用Redim动态数组即可. 1 2 3 4 5 6 7 8 Sub test1() Dim a() As Integer, iRow As Long, i As Integer iRow = Cells(Rows.Count, 1).End(xlUp).Row ReDim a(iRow - 1) For i = 1 To UBou