+ Reply to Thread
Results 1 to 8 of 8

VBA: Using a Loop to find an empty cell

  1. #1
    Registered User
    Join Date
    05-29-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    52

    VBA: Using a Loop to find an empty cell

    Hello!

    This is my first post and I made sure I couldn't find the answer before starting the new thread. I'm having trouble with the VB part of the User Form (I'm very new at this). The explanation to my project is under all the equal signs. The puzzle I'm attempting to fix is shown below for those of you who cannot afford to read a lot right now.

    So I want "i" to count up by 1 every time Excel reads something in a cell in each row in column 1. I want the code to run such that once excel finds an empty cell in a row column 1, the loop will stop running. Thing is, it never loops. It only goes once. So if I have say, (A2:A7) filled with something while A8 is empty, the code won't loop. It will seemingly ignore the loop and only add 1 to "i". It's as if the "Do" loop isn't there at all.

    I'm not at work but I know that if I can solve this one little part of the code, it'll all work:

    Do
    i = i + 1
    Loop Until IsEmpty(ActiveCell.Offset(1, 0))

    Any help is appreciated, thanks!



    ======================================================================================================================================

    I'm trying to allow a user to fill out a form (based on report data) and have the data entered into a sheet. The main "key", if you will, is the ID number of the report they want to enter. Then there are items which is associated with the data. There can be as many as 1 to 20 items per report entered. The thing is, the report items themselves have to be recorded such that they can be easily looked up, with the associated report ID shown as well.

    To these ends, I have decided to enter every item into the sheet in the 2nd column along with the associated report ID in the first column (therefore, the report ID's may often repeat as there are more than one item per report usually).

    In order to program the User Form, I was using a "Do" loop (as shown above) to allow the program to scan the first column until it found an empty cell. Then the report ID was to be placed in that empty cell. If there are, say, 2 items for this one report, I need the report ID listed again so that if item #2 is searched, there will be a report ID allotted to it.

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: VBA: Using a Loop to find an empty cell

    Hello and welcome to the forum.

    Maybe something like this?

    Please Login or Register  to view this content.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    05-29-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: VBA: Using a Loop to find an empty cell

    Hello,

    Thanks for the help, but for some reason, that loop is giving me a Count = 1048552. Since there are only 5 entries in column A (including the field name), Count should be equal to either 6 or 7 right?

  4. #4
    Registered User
    Join Date
    05-16-2012
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA: Using a Loop to find an empty cell

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: VBA: Using a Loop to find an empty cell

    Is the activecell the last row with data? If so, then it will give you a horendous number like that. Could you load an example of what you are trying to accomplish?

  6. #6
    Registered User
    Join Date
    05-29-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: VBA: Using a Loop to find an empty cell

    I was able to solve it, thanks to your help. Thanks everyone!

    I'll probably be back when I encounter something else.

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: VBA: Using a Loop to find an empty cell

    Glad it all worked out. Looping is fine with a small set of data but is very inefficient with all numbers of cells. So use it wisely.

    Good luck.

    abousetta

  8. #8
    Registered User
    Join Date
    05-29-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: VBA: Using a Loop to find an empty cell

    Really? I'm planning to use this to search for empty cells in a database of +3000 records. Anything I should know?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1