Message Input Box for Macro

ilcaa

Well-known Member
Joined
May 25, 2005
Messages
751
Office Version
  1. 365
Platform
  1. Windows
I have a macro that deletes repetitive rows. this one shows for Column E, if I want to change to look for items in column C I need to manually go to the macro editior and change it...I wanted a input box to show asking which column, then it would change the column letter in the macro accordingly....hope i made sense, please let me know if you have a solution...

=Sub DELETE_ADDRESSES()
For MY_ROWS = Range("E65536").End(xlUp).Row To 2 Step -1
If Range("E" & MY_ROWS).Value = Range("E" & MY_ROWS - 1).Value Then
Rows(MY_ROWS - 1).Delete
End If
Next MY_ROWS
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this

Code:
Sub DELETE_ADDRESSES()
Dim r As Range, i As Long, j As Integer
On Error Resume Next
Set r = Application.InputBox("Click in the column", Type:=8)
On Error GoTo 0
If r Is Nothing Then Exit Sub
j = r.Column
For i = Cells(Rows.Count, j).End(xlUp).Row To 2 Step -1
    If Cells(i, j).Value = Cells(i - 1, j).Value Then
        Rows(i - 1).Delete
    End If
Next i
End Sub
 
Upvote 0
Hello,

If you want to type in a column try

Code:
Sub DELETE_ADDRESSES()
    MY_COL = InputBox("Which column?", "DATA ENTRY")
    For MY_ROWS = Range(MY_COL & "65536").End(xlUp).Row To 2 Step -1
        If Range(MY_COL & MY_ROWS).Value = Range(MY_COL & MY_ROWS - 1).Value Then
            Rows(MY_ROWS - 1).Delete
    End If
    Next MY_ROWS
End Sub

this has no error checking though.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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