Andrey has attended:
Excel Advanced - Formulas & Functions course
Excel VBA Introduction course
Excel VBA range
Hello,
I want to create a range that includes county codes, for example, Range "Country" = JP, MX, US, CL and BG. And I want a code/loop as follows:
- If the Cell (in column AI) contains a county code from that range, Then do not delete the row
Else Delete the row
Can you please advise what the code would look like?
Thank you and Regards,
Andrey
RE: Excel VBA range
Hi Andrey
Thanks for question.
Here's a way to delete the rows with unwanted country codes.
Sub Remove()
Range("AI2").Select
Do Until ActiveCell = ""
If ActiveCell <> "JP" And ActiveCell <> "MX" And ActiveCell <> "US" And ActiveCell <> "CL" And ActiveCell <> "BG" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Loop
End Sub
Assumes the data is in a range starting from AI2 and ending with a blank cell.
Save your file before testing.
Regards
Doug
STL