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

excel vba range

ResolvedVersion 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:

Calculate age or service

The DATEDIF() function in Excel calculates the number of days, months, or years between two dates. So, this function makes it easy to calculate a person's age. To try this tip:

In a blank worksheet, type the birth date in cell A1, using slashes to separate day, month, and year.
In cell A2, type =DATEDIF(A1,TODAY(),"y") and press ENTER.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.