using range address from input box

ahmed sousi

New Member
Joined
Sep 25, 2015
Messages
3
in below vba code , i would like to replace all "B" in this code by range selecting or entering from application input box , kindly advise ,


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
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The code could look like this
Code:
Sub ahmed_code()
    Dim lr As Long, r As Long, x As Long
    
    inr = InputBox("Enter the Column alphabet:")
    Application.ScreenUpdating = False
    lr = Range(inr & Rows.Count).End(xlUp).Row
    For r = lr To 2 Step -1
        x = WorksheetFunction.CountIf(Range("Sheet2!$A:$A"), Cells(r, inr))
        If x = 0 Then
            Cells(r, inr).Resize(, 500).Delete Shift:=xlUp
        End If
    Next r
    Application.ScreenUpdating = True
    
    MsgBox "DONE YA M3alem ... Ahmed.Sousi ^_^ "
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top