+ Reply to Thread
Results 1 to 4 of 4

Find/Count Cell until first empty cell

  1. #1
    Registered User
    Join Date
    03-25-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    34

    Find/Count Cell until first empty cell

    I have a spreadsheet with data columns formatted as follows:

    Title
    1
    2
    3
    4
    5
    (Blank Cell)
    Verbage

    I used excel recorder and generated the following code:

    'Enter Formulas into CarAllow Sheet
    Range("E2").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(C[-2],C[3]:C[4],2,0)"
    Range("E2").Select 'CHECK RANGE
    Selection.AutoFill Destination:=Range("E2:E74") 'CHECK RANGE VLOOKUP
    Range("E2:E74").Select 'CHECK RANGE VLOOKUP
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-1]"
    Range("F2").Select
    Selection.AutoFill Destination:=Range("F2:F74") 'CHECK RANGE
    Range("F2:F74").Select 'CHECK RANGE
    Range("J2").Select
    ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-2],R2C3:R7000C6,4,FALSE),0)"
    Range("J2").Select
    Selection.AutoFill Destination:=Range("J2:J855") 'CHECK RANGE IFERROR, VLOOKUP
    Range("J2:J855").Select 'CHECK RANGE IFERROR, VLOOKUP
    Range("K2").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-1]=0,RC[-2],RC[-1])"
    Range("K2").Select
    Selection.AutoFill Destination:=Range("K2:K855") 'CHECK RANGE IF STATMENT
    Range("K2:K855").Select 'CHECK RANGE IF STAMENT

    This code works well for my specific first run of data, yet the data is merged from an ever changing database. Therefore the number of data sets will change through time. The lower range limits are correct, yet the upper ones should be variable depending on the imported data size.
    For example:

    Selection.AutoFill Destination:=Range("E2:E74") 'CHECK RANGE VLOOKUP
    Range("E2:E74").Select 'CHECK RANGE VLOOKUP

    For this code E74 should be the last cell before the blank and not the fixed 74 value. Would dropping the 74 part do this? Or is there a way to count the column data before the first blank space and insert as "E"&N, where N=last cell before blank.

    I hope this is clear.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Find/Count Cell until first empty cell

    Try:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-25-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    34

    Re: Find/Count Cell until first empty cell

    In this formula you are replacing the 1LR variable and applying it to the second range dimension. Would you keep them like that or maybe name the second 1LR a diferent thing? Im trying to understand the logic in the code.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Find/Count Cell until first empty cell

    Dohhhh ....

    In your example, the first two ranges went down to 74. the second two ranges went down to 855. The lLR variable is only needed long enough to set up the formulae, so I used it for the first two ranges and then updated/replaced the value for the second two ranges.

    In fact, I'm wrong, in that I should have been using a column that is populated, not the cells that will receive the formula ... I confused myself by looking at the two numbers .

    So, in fact, it should probably be something like this:

    Please Login or Register  to view this content.
    Hope that makes more sense.

    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 05-13-2014, 10:19 AM
  2. Need to find empty filled cells in a column and copy to the empty cell below
    By Grahamfeeley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-30-2014, 10:09 AM
  3. [SOLVED] How to count a cell with a number or letter as 1 or an empty cell as 0
    By garrett.grillo in forum Excel General
    Replies: 4
    Last Post: 03-05-2012, 09:44 AM
  4. Replies: 4
    Last Post: 06-24-2010, 11:13 AM
  5. Replies: 1
    Last Post: 03-02-2010, 01:23 PM

Tags for this Thread

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