Results 1 to 12 of 12

Ignore blanks in Compile workbooks code

Threaded View

  1. #1
    Registered User
    Join Date
    04-08-2015
    Location
    Chamonix
    MS-Off Ver
    2007
    Posts
    9

    Ignore blanks in Compile workbooks code

    Hello all, I have been working on a code allowing me to compile many workbooks via a VBA macro, trouble is that in the set range there are many blank cells.

    Is there an easy way to ignore the blank cells?

    Code:

    Sub MergeAllWorkbooks()
        Dim SummarySheet As Worksheet
        Dim FolderPath As String
        Dim NRow As Long
        Dim FileName As String
        Dim WorkBk As Workbook
        Dim SourceRange As Range
        Dim DestRange As Range
        
        Set SummarySheet = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
        
        FolderPath = "C:\Users\repsuser\Documents\MACRO DEV\Test\test cashbooks\"
        
        NRow = 1
        
        FileName = Dir(FolderPath & "*.xl*")
        
        Do While FileName <> ""
            
            Set WorkBk = Workbooks.Open(FolderPath & FileName)
            
            SummarySheet.Range("A" & NRow).Value = FileName
            
            Set SourceRange = WorkBk.Worksheets(1).Range("B18:N100")
            
            Set DestRange = SummarySheet.Range("B" & NRow)
            Set DestRange = DestRange.Resize(SourceRange.Rows.Count, _
               SourceRange.Columns.Count)
            
            DestRange.Value = SourceRange.Value
             
            NRow = NRow + DestRange.Rows.Count
            
            WorkBk.Close savechanges:=False
            
            FileName = Dir()
        Loop
        
        SummarySheet.Columns.AutoFit
    End Sub


    Many thanks
    Last edited by MichaelHopkins; 04-10-2015 at 04:00 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Code Needed - Move Data/Ignore Blanks/Data is Moved to Specific Area
    By kbarnes04 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-22-2014, 03:30 PM
  2. [SOLVED] MIN/MAX IF To Ignore Blanks
    By splendidus in forum Excel General
    Replies: 2
    Last Post: 07-04-2012, 04:00 PM
  3. Compile Errors - Is it possible to ignore them?
    By Shane O in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-13-2011, 09:45 AM
  4. VB code help, ignore blanks/specific
    By ad9051 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-08-2011, 04:38 PM
  5. Concatenate and ignore blanks
    By nujwaan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2009, 04:25 AM

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