经验直达:
- VBAexcel脚本编写求助
- 怎么用EXCEL的VBA脚本进行行的操作
一、VBAexcel脚本编写求助
Sub kerting()
Dim rng As Range, rng1 As Range
Dim r%, r1%, i%, j%
With Sheet1
.Cells.Interior.Pattern = xlNone
r = .Cells(.Rows.Count, 1).End(3).Row
r1 = .Cells(.Rows.Count, 6).End(3).Row
For i = 2 To r1
For j = 2 To r
If .Cells(i, 1) = .Cells(j, 6) Then
If .Cells(i, 2) <> .Cells(j, 7) Then
If Not rng Is Nothing Then
Set rng = Union(rng, .Cells(j, 7))
Else
Set rng = Cells(j, 7)
End If
Else
If Not rng1 Is Nothing Then
Set rng1 = Union(rng1, .Cells(j, 7))
Else
Set rng1 = Cells(j, 7)
End If
End If
End If
Next
Next
rng.Interior.Color = 255 '红色表示只有一列数据可以上
rng1.Interior.Color = 12611584 '蓝色表示两列数据均可以对上
End With
End Sub
没有实例数据,请参照此例;
二、怎么用EXCEL的VBA脚本进行行的操作
Alt F11 , 输入以下代码便可:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For i = 1 To 100 '获取第一行的单元格数量
If Cells(1, i).Valuehttps://www.itzhengshu.com/excel/= "" Then Exit For
a = a1
Next i
For i = 1 To 100 '获取第二行的单元格数量
If Cells(2, i).Valuehttps://www.itzhengshu.com/excel/= "" Then Exit For
b = b1
Next i
For i = 1 To b
For j = 1 To a
Cells(3, k1) = Cells(2, i) & "->" & Cells(1, j)
k = k1
Next j
Next i
End Sub
结果:
【怎么用EXCEL的VBA脚本进行行的操作 VBAexcel脚本编写求助】