2015-09-25 45 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