Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 487491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:36:37+00:00 2026-05-13T01:36:37+00:00

I’m trying to loop through a set of cells using VBA in a worksheet

  • 0

I’m trying to loop through a set of cells using VBA in a worksheet and check if they contain any data.
My spreadsheet is like:

   __A_____B_____C_____D____E_____F____G
 1| 3122  -1    -1   3243   
 2| -1    -1    -1   3243   1     1    1
 3| -1    -1    -1   3255         1
 5| 4232 2132   -1   3259
 6| 7544 1333   324  3259
 7| -1    -1    -1   3259   1     2    1
 8| -1    -1    -1   3259   1     1    1
 9| -1    -1    -1   3267
10| 2121  222   -1   3267

I want to get rid of the rows that don’t have any data in columns E F and G but I’m not sure how to loop through the rows and columns. I have seen many instructions for looping down a column but I can’t find anything on how to loop in two dimensions checking the cells for data.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:36:37+00:00Added an answer on May 13, 2026 at 1:36 am

    This should work:

    Sub main()
    
    Dim maxRow As Integer
    Dim currentRow As Integer
    
    With Worksheets("Sheet1")
        maxRow = .Range("A1").CurrentRegion.Rows.Count
    
        Dim i As Integer
        ' Start at the bottom and work upwards
        For i = maxRow To 1 Step -1
            ' 5 represents column E, 6 is column F and 7 is column G
            If (.Cells(i, 5).Value = "" And .Cells(i, 6).Value = "" And _
                .Cells(i, 7).Value = "") Then
                .Rows(i).Delete
            End If
        Next i
    End With
    
    End Sub
    

    Because there are only three columns to check, it’s easy to just use And to join the three checks together. In a more complex situation, a nested For loop as in Adam Bernier’s answer would be better

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.