2015-09-25 28 views
0

我正在使用下面的VBA代码来匹配和删除Excel中的一些数据, 我想使用应用程序输入框输入所需的列名称并将“B”替换为我的代码,通过这个入口数据用于Excel应用程序输入框的VBA代码

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