[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

VBA Combining workbooks/worksheets - Copy data from rows where column C is not blank

Asked by jasocke2 in Microsoft Excel Spreadsheet Software, Microsoft Office Suite, Automation

Tags: VBA, combining workbooks, merge

Hi.

I have the attached 2 example workbooks (& the code) which merges the worksheets from 7 different workbooks together into a 'Raw data' worksheet in my master workbook.

It is driven off a parameters table which allows you to select which workbooks/worksheets you want to include in the merge. - The code works fine however when it is copying the data from each worksheets it is just copying all the data as a 'block' copy where I need it do do it row by row becuase I dont want to copy the row if colum C in each row contains no data, ie. it is blank.

So in my code I need another loop which will:
Copy data from column A - E for each row if column C is not blank from workbook1
Paste into Column B - F in Raw Data worksheet (as column A contains the source filename) in master workbook
Loop until it reaches no more data

I ideally just want to copy the specific range as above, not the whole row but either will do.

This is my code, please refer to attachment too which includes master workbook and an data entry workbook where the data comes from.

I don't really want to use autofiltering to get the non blank data I would rater do it cell by cell/row by row checking everytime if column C is blank or not.

With the attached save and change directory in master file

Any help would be most appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
Option Explicit
 
Sub OpenWorkbooks()
'------
Dim Book_Name As range  ' List of available books
Dim Sheet_Name As range ' List of available sheets
Dim dLastRow As Long
Dim oLastRow As Long
Dim sLastRow As Long
Dim DestinationSheet As Worksheet
Dim SourceSheet As Worksheet
Dim WorkBookList As range
Dim WorkSheetList As range
Dim WorkbookPath As String
 
 
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
        .EnableEvents = False
    End With
    
        'set source and destination sheet
    Set DestinationSheet = Sheets("Raw Data")
    Set SourceSheet = Sheets("Parameters")
    
      
    With SourceSheet
        ' Path of the workbooks
        WorkbookPath = range("C4")
        ' List of available workbooks
        Set WorkBookList = range("D5:D16")
        ' List of available worksheets
        Set WorkSheetList = range("F5:F16")
    End With
    
 
    With DestinationSheet
        ' Delete any exsisting data and paste in row after heading
        dLastRow = range("A" & Rows.Count) + 2
        'Save
        oLastRow = dLastRow
        
        
        ' for each book name in the workbook list
        For Each Book_Name In WorkBookList
        ' If cell next to it has a Y or y in it then open workbook, if anything else raise error
        If UCase(Book_Name.Offset(0, 1)) = "Y" Then
            Workbooks.Open WorkbookPath & Book_Name
 
        ' for each sheet name in the sheetname list
        For Each Sheet_Name In WorkSheetList
'------------------------------------------------------------------------------------------
        ' If cell next to it has a Y or y in it then use worksheet, if anything else dont
        If UCase(Sheet_Name.Offset(0, 1)) = "Y" Then
            'Where from
        Set SourceSheet = ActiveWorkbook.Sheets(Sheet_Name.Value)
            'Get last row of data
            sLastRow = SourceSheet.range("A" & Rows.Count).End(xlUp).Row
            'If data
        If sLastRow > 1 Then
            'Copy
            SourceSheet.range("A3:E" & sLastRow).Copy .range("B" & dLastRow)
            'Get new last row of destination
            dLastRow = .range("B" & Rows.Count).End(xlUp).Row + 1
            'Put workbook name into first column
            .range("A" & oLastRow & ":A" & dLastRow - 1) = Book_Name.Value
            'Save
            oLastRow = dLastRow
'---------------------------------------------------------------------------------------------
 
        End If
        End If
        'next sheet in list
        Next Sheet_Name
        'close workbook
            ActiveWorkbook.Close True
        End If
        
        'Next workbook
        Next Book_Name
        
    End With
    
 
'------
    ' Message to user that import is complete
    MsgBox ("Data refresh complete"), vbInformation, "Done!"
'------
    ' set all to nothing
    Set Book_Name = Nothing
    Set Sheet_Name = Nothing
    Set DestinationSheet = Nothing
    Set SourceSheet = Nothing
    Set WorkBookList = Nothing
    Set WorkSheetList = Nothing
    
'------
    ' turn functions back on
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
        .EnableEvents = True
    End With
 
 
End Sub
Attachments:
 
Example file as described above
 
 
Related Solutions
 
Loading Advertisement...
 
[+][-]09/15/09 10:34 AM, ID: 25337250Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/15/09 01:01 PM, ID: 25338738Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/15/09 03:38 PM, ID: 25340325Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/16/09 01:38 AM, ID: 25343237Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/16/09 04:22 AM, ID: 25344215Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/16/09 04:26 AM, ID: 25344235Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/16/09 08:36 AM, ID: 25346781Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/16/09 09:16 AM, ID: 25347265Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Microsoft Excel Spreadsheet Software, Microsoft Office Suite, Automation
Tags: VBA, combining workbooks, merge
Sign Up Now!
Solution Provided By: sirplus
Participating Experts: 2
Solution Grade: A
 
[+][-]09/16/09 09:32 AM, ID: 25347448Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/17/09 12:57 AM, ID: 25353663Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/17/09 01:27 AM, ID: 25353831Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625