我正在使用以下VBA代码来匹配和删除Excel中的一些数据, 我想使用应用程序输入框输入所需的列名,并通过此条目数据替换我的代码中的“B”
Sub ahmed_code()
Dim lr As Long, r As Long, x As Long
Application.ScreenUpdating = False
lr = Range("B" & Rows.Count).End(xlUp).Row
For r = lr To 2 Step -1
x = WorksheetFunction.CountIf(Range("Sheet2!$A:$A"), Cells(r, "B"))
If x = 0 Then
Cells(r, "B").Resize(, 500).Delete Shift:=xlUp
End If
Next r
Application.ScreenUpdating = True
MsgBox "DONE YA M3alem ... Ahmed.Sousi ^_^ "
End Sub
答案 0 :(得分:0)
使用以下代码:
Sub PickColumn()
Dim r As Range, MyCol As String
Set r = Application.InputBox(Prompt:="click a cell in the column", Type:=8)
MyCol = Split(r.Address, "$")(1)
MsgBox MyCol
End Sub
并在您的代码中将“B”替换为MyCol