98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA range
Excel VBA range
Resolved · Medium Priority · Version 2010
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
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Creating charts in Excel 2010Here's how to present your data in a chart format: |