Please help with input box

jah01653

New Member
Joined
May 18, 2015
Messages
5
Hello, below VBA code works for me, i am comparing 2 columns and deleting the entire row if the values are the same. the columns to compare will vary, so i need to add input box(es) so that the user can put in the 2 columns that they want to compare.

Sub Delete_Same_City()
'delete row if property city in Column D and mailing city in column AC are the same


Dim endRow As Long


endRow = Sheet1.Range("A999999").End(xlUp).Row
For i = 1 To endRow
If Sheet1.Range("D" & i).Value = Sheet1.Range("AC" & i).Value Then
Sheet1.Range("AC" & i).EntireRow.Delete

End If
Next i


End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
How about
Code:
Sub jah01653()
   Dim EndRow As Long, i As Long
   Dim Cols As String, Col1 As String, Col2 As String
   
   Cols = InputBox("Please enter the two columns like D,AC")
   Col1 = Split(Cols, ",")(0)
   Col2 = Split(Cols, ",")(1)
   EndRow = Sheet15.Range("A" & Rows.Count).End(xlUp).Row
   
   For i = EndRow To 1 Step -1
      If Sheet15.Range(Col1 & i).Value = Sheet15.Range(Col2 & i).Value Then
         Sheet15.Rows(i).Delete
      End If
   Next i
End Sub
 
Upvote 0
Thanks Fluff! works great.

How about
Code:
Sub jah01653()
   Dim EndRow As Long, i As Long
   Dim Cols As String, Col1 As String, Col2 As String
   
   Cols = InputBox("Please enter the two columns like D,AC")
   Col1 = Split(Cols, ",")(0)
   Col2 = Split(Cols, ",")(1)
   EndRow = Sheet15.Range("A" & Rows.Count).End(xlUp).Row
   
   For i = EndRow To 1 Step -1
      If Sheet15.Range(Col1 & i).Value = Sheet15.Range(Col2 & i).Value Then
         Sheet15.Rows(i).Delete
      End If
   Next i
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,108
Members
452,544
Latest member
aush

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