我正在学习excel中的vba。我在这里遇到了问题。
我在这里尝试完成的是
这是示例文件
https://a.uguu.se/tkGV68TzIGwR_testtt111.xlsx
这是我到目前为止所得到的。当columnC为空时,我可以在ColumnB中选择值,并将它们复制到另一列。
Sub compareWR()
Dim emptyI As Long
Dim emptyJ As Long
lastrow = ws1.Cells(Rows.Count, "B").End(xlUp).Row
emptyJ = 2
For emptyI = 2 To lastrow
If Cells(emptyI, "C").Value = "" Then
Cells(emptyJ, "AA").Value = Cells(emptyI, "B").Value
emptyJ = emptyJ + 1
End If
Next emptyI
End Sub
答案 0 :(得分:0)
似乎某些条件格式规则应该处理您需要的所有内容。他们在VBA。
Option Explicit
Sub CFRs()
Dim addr1 As String, addr2 As String
With Worksheets("sheet1")
With .Range(.Cells(1, "B"), .Cells(.Rows.Count, "B").End(xlUp))
addr1 = .Cells(1).Address(False, True)
addr2 = .Cells(1).Offset(0, 1).Address(False, True)
.FormatConditions.Delete
With .FormatConditions.Add(Type:=xlExpression, _
Formula1:="=AND(" & addr2 & "=TEXT(,), ISNUMBER(MATCH(" & addr1 & ", Sheet2!$O:$O, 0)))")
.Interior.ColorIndex = 10
End With
With .FormatConditions.Add(Type:=xlExpression, _
Formula1:="=NOT(LEN(" & addr2 & "))")
.Interior.ColorIndex = 6
End With
End With
End With
With Worksheets("sheet2")
With .Range(.Cells(1, "O"), .Cells(.Rows.Count, "O").End(xlUp))
addr1 = .Cells(1).Address(False, True)
.FormatConditions.Delete
With .FormatConditions.Add(Type:=xlExpression, _
Formula1:="=ISNA(MATCH(" & addr1 & ", Sheet1!$B:$B, 0))")
.Interior.ColorIndex = 3
End With
End With
End With
End Sub