Excel vba for loop

0 votes
Sub letr()

Dim i As Integer

For i = 3 To 25

    If Cells(i, 7) <> "CA" Then
    Rows(i).Delete
    End If

Next i

End Sub

The above code does not delete all the results(Total 4). i have to run the code twice to delete all the 4 results. Can anyone show me what i did wrong?

Apr 5 in Database by Edureka
• 13,640 points
68 views

1 answer to this question.

0 votes
You must understand how to use loops effectively in Excel and VBA to get the most out of them.

Loops in VBA allow you to go through a set of objects/values one by one and analyse them. For each loop, you can also conduct particular activities.

Here's a quick example of how to use VBA loops in Excel.

In practise, VBA loops in Excel can help you automate activities in a variety of ways.

Here are a few additional examples of how VBA loops can be helpful:

Iterating over a set of cells and inspecting each one (highlight cells with a specific text in it).
Looping through all of the worksheets and doing something with each one (for example, protecting or unprotecting it).
Go through all of the open workbooks in a loop (and save each workbook or close all except the active workbook).
Iterate over all of the characters in a cell (and extract the numeric part from a string).
All the values in an array are looped through.
Iterate across all of the charts/objects (and give a border or change the background color).
answered Apr 5 by gaurav
• 13,460 points

Related Questions In Database

0 votes
0 answers

How to loop in excel without VBA or macros?

Is it possible to iterate (loop) a ...READ MORE

Mar 30 in Database by Edureka
• 13,640 points
177 views
0 votes
1 answer

Syntax of for-loop in SQL Server

TSQL has no for-loop, we have only ...READ MORE

answered Feb 15 in Database by Neha
• 8,560 points
28 views
0 votes
1 answer

Convert a number to a letter in C# for use in Microsoft Excel [duplicate]

If you are familiar with using formulas ...READ MORE

answered Feb 23 in Database by gaurav
• 13,460 points
44 views
0 votes
1 answer

MS Excel - SumProduct formula with Loop

Drag this to the right of cell ...READ MORE

answered Mar 14 in Database by gaurav
• 13,460 points
27 views
0 votes
1 answer

Number of elements in a single dimension variant array in excel

You must do UBound - LBound + ...READ MORE

answered Mar 24 in Database by gaurav
• 13,460 points
64 views
0 votes
1 answer

Pasting an Excel range into an email as a picture

Hold down the ALT + F11 keys ...READ MORE

answered Mar 30 in Database by gaurav
• 13,460 points
87 views
0 votes
0 answers

Unprotect workbook without password

I have a popular VBA code to ...READ MORE

Apr 7 in Database by Edureka
• 13,640 points
27 views
0 votes
1 answer

Excel VBA run-time error 1004 : Application-defined or object-defined error

Maybe your code is on Sheet 1, ...READ MORE

answered Apr 11 in Database by gaurav
• 13,460 points
265 views
0 votes
1 answer

Excel VBA - exit for loop

When we need to depart the For ...READ MORE

answered Mar 15 in Database by gaurav
• 13,460 points
38 views
0 votes
1 answer

#NAME? error in Excel for VBA Function

Because you have a module with the ...READ MORE

answered Apr 5 in Database by gaurav
• 13,460 points
51 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP