excel vba range

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA range

Excel VBA range

resolvedResolved · Medium Priority · Version 2010

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

Edited on Mon 19 Dec 2016, 10:24

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

RE: Excel VBA range

Thank you very much, Doug! Much appreciated, indeed!

Kind Regards,

Andrey

 

Training courses

 

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Creating charts in Excel 2010

Here's how to present your data in a chart format:

Highlight the data you wish to use in a chart

Click the Insert Ribbon

In the Charts Group, select Column Chart

Your chart will then appear on your work sheet.

View all Excel hints and tips


Server loaded in 0.07 secs.