我有两张excel表,我需要进行细胞比较。 需要宏观解决方案。
纸张1具有A-N列,而纸张2具有A-S列
我需要先检查表2中F列中每列B的值(B1:B2000)是否可用。 如果可用,则选择shee2中A列中的值,并将其粘贴到表1中的列O中。
对不起任何细节问题表示歉意。 无论如何都找不到这个问题......
答案 0 :(得分:1)
放手一搏,
Sub Button1_Click()
Dim ws As Worksheet, sh As Worksheet
Dim wsRws As Long, wsRng As Range, w As Range
Dim shRws As Long, shRng As Range, s As Range
Set ws = Sheets("Sheet1")
Set sh = Sheets("Sheet2")
With ws
wsRws = .Cells(Rows.Count, "B").End(xlUp).Row
Set wsRng = .Range(.Cells(1, "B"), .Cells(wsRws, "B"))
End With
With sh
shRws = .Cells(Rows.Count, "F").End(xlUp).Row
Set shRng = .Range(.Cells(1, "F"), .Cells(shRws, "F"))
End With
For Each w In wsRng
For Each s In shRng
If w = s Then w.Offset(0, -1) = s.Offset(0, -5)
Next s
Next w
End Sub