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, 2022 in Database by Edureka
• 13,670 points
431 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, 2022 by gaurav
• 23,260 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, 2022 in Database by Edureka
• 13,670 points
2,059 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, 2022 in Database by Neha
• 9,060 points
720 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, 2022 in Database by gaurav
• 23,260 points
601 views
0 votes
1 answer

MS Excel - SumProduct formula with Loop

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

answered Mar 14, 2022 in Database by gaurav
• 23,260 points
393 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, 2022 in Database by gaurav
• 23,260 points
543 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, 2022 in Database by gaurav
• 23,260 points
4,206 views
0 votes
0 answers

Unprotect workbook without password

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

Apr 7, 2022 in Database by Edureka
• 13,670 points
297 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, 2022 in Database by gaurav
• 23,260 points
3,563 views
0 votes
1 answer

Excel VBA - exit for loop

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

answered Mar 15, 2022 in Database by gaurav
• 23,260 points
589 views
0 votes
1 answer

#NAME? error in Excel for VBA Function

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

answered Apr 5, 2022 in Database by gaurav
• 23,260 points
1,119 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP