+ Reply to Thread
Results 1 to 12 of 12

How can I ignore blank rows in this VB

  1. #1
    Registered User
    Join Date
    11-07-2013
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016
    Posts
    52

    How can I ignore blank rows in this VB

    Hi Guys, I'm really hoping you can help. I'm a bit of a novice as visual basic goes but I'm trying to learn.
    I'm using Ron de Bruin's code here and its almost there, I've been reading in I don't know how many forums and I just cant find the answer.

    I'm trying to get the code to skip the blank rows in the group of spreadsheets I need to consolidate. Using Ron's code below, I've created export.xlsx from five data sheets book1, book2, book3, book4 and Timesheet IGW Week 45 2013.xlsx, these are exports from another workbook, the names are not important but I've attached the files for convenience.

    In the file export.xlsx you will see a lot of lines with #N/A and 0 that I am trying to filter out in the consolidation process.
    Column C is hidden in the data sheets I'm consolidating from so I'd like to avoid that all together if possible. Also of note is that cells b11:b28 and d11:d28 are data validation cells from the original master sheet.

    Here's my thinking:-
    In the section "Set sourceRange = .Range("b8:t30")" , could I use "Set sourceRange = .Range("b8:b30, d8:t30")" to avoid column C?
    I tried using "LastRow" but the debug kept stopping there so not sure what I was doing wrong.

    Any help or advice would be greatly appreciated.

    Ginge.


    Ron's code, with paths edited to suit my system.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Ginge1267; 11-14-2013 at 04:20 AM. Reason: Pls use code tags around your codes as per forum rules.

  2. #2
    Registered User
    Join Date
    11-07-2013
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016
    Posts
    52

    Re: How to ignore blank rows in this VBS?

    Please can anyone help?
    Last edited by Ginge1267; 11-14-2013 at 04:19 AM.

  3. #3
    Registered User
    Join Date
    11-07-2013
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016
    Posts
    52

    Re: How can I ignore blank rows in this VB

    Please can anyone help? Have I not explained it very well?

  4. #4
    Registered User
    Join Date
    11-07-2013
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016
    Posts
    52

    Re: How can I ignore blank rows in this VB

    What I have tried:-
    I added a second range see below as the line I tried first (Set sourceRange = .Range("b8:b30, d8:t30") didn't work.

    This works for missing out column C, can anyone help with the rows?
    Please Login or Register  to view this content.
    Set sourceRange = .Range("b8:b30")
    Set sourceRange = .Range("d8:t30")
    Please Login or Register  to view this content.

    EDIT - Actually it didn't work, it completely misses out everything before Column D, damn!
    Last edited by Ginge1267; 11-14-2013 at 06:00 AM. Reason: Didn't work as I first thought

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How can I ignore blank rows in this VB

    I think the easiest and most efficient way would be to copy all relevant range, including the blanks in to summary( Master) sheet, then with 2-3 lines of a code, you can delete the blank rows from the summary sheet.

  6. #6
    Registered User
    Join Date
    11-07-2013
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016
    Posts
    52

    Re: How can I ignore blank rows in this VB

    Quote Originally Posted by AB33 View Post
    I think the easiest and most efficient way would be to copy all relevant range, including the blanks in to summary( Master) sheet, then with 2-3 lines of a code, you can delete the blank rows from the summary sheet.
    Hi AB33, yes I agree, that's exactly what I'm trying to do now. I've added the code below but it's deleting rows I didn't expect it to. I am copying from other examples of similar requests and trying to understand it. Can you tell me please, what exactly does the ".SpecialCells(4).EntireRow.Delete" do?

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How can I ignore blank rows in this VB

    It deletes if a cell in range c is blank. By blank, I mean not necessary a cell which has formula with blank string.
    I have expanded the range you want to look for empty cells, so in this case, the code looks for empty columns in A-Z. If your range is fewer, you need to adjust it.
    You are also replacing the error values with empty and delete them too.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-07-2013
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016
    Posts
    52

    Re: How can I ignore blank rows in this VB

    Quote Originally Posted by AB33 View Post
    It deletes if a cell in range c is blank. By blank, I mean not necessary a cell which has formula with blank string.
    I have expanded the range you want to look for empty cells, so in this case, the code looks for empty columns in A-Z. If your range is fewer, you need to adjust it.
    You are also replacing the error values with empty and delete them too.
    Please Login or Register  to view this content.
    Perfect, Yes I wanted the error values cleared, I've added a "." to the rows I don't want it to delete to column C, then as it deletes column C after deleting the 0 rows, the "." are cleared anyway and it doesn't delete the rows that I didn't want it to.

    I'll try yours too to see how it effects.

    Many Thanks for your help.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How can I ignore blank rows in this VB

    So, what is missing?

  10. #10
    Registered User
    Join Date
    11-07-2013
    Location
    Derbyshire, England
    MS-Off Ver
    Excel 2016
    Posts
    52

    Re: How can I ignore blank rows in this VB

    As I had told it to delete all rows in column C that were blank or 0 after making the errors blank. Certain rows like where my total was didn't have anything in column C. By adding the "." to the rows I don't want deleted it now works perfectly.

    Is that what you meant?

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How can I ignore blank rows in this VB

    Is that what you meant?
    What I want is you get the solution. That is what matters.

  12. #12
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How can I ignore blank rows in this VB

    Hi,

    The simplest way I know of deleting unwanted rows is to set up a filter which displays only the unwanted rows then use a

    Please Login or Register  to view this content.
    syntax to delete the rows. This assumes row 1 contains the column headers which you don't want to delete
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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. IF blank ignore
    By dbyrne88 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-17-2013, 10:36 AM
  2. How can I make a macro ignore blank cells? - Blank Cells have formulas
    By mz1161 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2013, 08:54 AM
  3. A4 = A1 OR A2 OR A3 (Ignore blank)
    By ThomasCarter in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-23-2013, 02:00 PM
  4. Query + Ignore Empty/Blank Rows
    By UberSlackr in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-01-2012, 11:01 PM
  5. [SOLVED] Ignore blank rows to populate custom drop down list column range
    By vidtec in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2006, 02:30 PM

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