+ Reply to Thread
Results 1 to 19 of 19

macro consolidates data from worksheets - question

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    macro consolidates data from worksheets - question

    hi

    i have the following code:

    Private Sub Worksheet_Activate()
    Dim Sh As Worksheet
    Dim Newsh As Worksheet
    Dim LR As Long, NR As Long
    
    Application.ScreenUpdating = False
    
    Set Newsh = ThisWorkbook.Sheets(Sheet20.Name)
    Newsh.Range("C12").CurrentRegion.Offset(1).Clear
    NR = 9
    
        
        For Each Sh In ThisWorkbook.Worksheets
            If Sh.Name Like "*" And Sh.Name <> Sheet7.Name And Sh.Name <> Sheet1.Name And Sh.Name <> Sheet19.Name And Sh.Name <> Sheet18.Name And Sh.Name <> Sheet17.Name And Sh.Name <> Sheet16.Name And Sh.Name <> Sheet15.Name And Sh.Name <> Sheet14.Name And Sh.Name <> Sheet13.Name And Sh.Name <> Sheet12.Name And Sh.Name <> Sheet11.Name And Sh.Name <> Sheet10.Name And Sh.Name <> Sheet19.Name And Sh.Name <> Sheet20.Name And Sh.Name <> Sheet20.Name And Sh.Visible Then
                LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
                If LR > 8 Then
                    Sh.Range("C13:AJ" & LR).Copy
                    Newsh.Range("C" & NR).PasteSpecial xlPasteFormats
                    Newsh.Range("C" & NR).PasteSpecial xlPasteAll
                    LR = Newsh.Range("C" & Rows.Count).End(xlUp).Row
                    Newsh.Range("A" & NR, "A" & LR) = Sh.Name
                    NR = LR + 1
       
                End If
            End If
        Next Sh
        
    Application.ScreenUpdating = True
    
    End Sub
    the issue:
    i would like for the macro to paste the data start from cell C13:AJ

    it works..but its pasting the data now in row 13 of column C....can someone pls help and advise?
    Last edited by jw01; 04-03-2012 at 09:07 AM.

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    Where do you want the data to paste? this will paste starting at C1, you can modify the commented row as needed

    Private Sub Worksheet_Activate()
    Dim Sh As Worksheet
    Dim Newsh As Worksheet
    Dim LR As Long, NR As Long
    
    Application.ScreenUpdating = False
    
    Set Newsh = ThisWorkbook.Sheets(Sheet20.Name)
    Newsh.Range("C12").CurrentRegion.Offset(1).Clear
    NR = 9
    
        
        For Each Sh In ThisWorkbook.Worksheets
            If Sh.Name Like "*" And Sh.Name <> Sheet7.Name And Sh.Name <> Sheet1.Name And Sh.Name <> Sheet19.Name And Sh.Name <> Sheet18.Name And Sh.Name <> Sheet17.Name And Sh.Name <> Sheet16.Name And Sh.Name <> Sheet15.Name And Sh.Name <> Sheet14.Name And Sh.Name <> Sheet13.Name And Sh.Name <> Sheet12.Name And Sh.Name <> Sheet11.Name And Sh.Name <> Sheet10.Name And Sh.Name <> Sheet19.Name And Sh.Name <> Sheet20.Name And Sh.Name <> Sheet20.Name And Sh.Visible Then
                LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
                If LR > 8 Then
                    Sh.Range("C13:AJ" & LR).Copy
                    Newsh.Range("C1").PasteSpecial xlPasteFormats 'Paste Destination
                    Newsh.Range("C1").PasteSpecial xlPasteAll 'Paste Destination
                    LR = Newsh.Range("C" & Rows.Count).End(xlUp).Row
                    Newsh.Range("A" & NR, "A" & LR) = Sh.Name
                    NR = LR + 1
       
                End If
            End If
        Next Sh
        
    Application.ScreenUpdating = True
    
    End Sub
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    hey thxs for your help

    i have changed the cel to b13...but for some reason it's not consolidating the data from all the unhidden worksheets? can u pls help?

    *see link*..im having some issue uploading :S

    https://skydrive.live.com/redir.aspx...CBc3-EgrNCjfgk


    Private Sub Worksheet_Activate()
    Dim Sh As Worksheet
    Dim Newsh As Worksheet
    Dim LR As Long, NR As Long
    
    Application.ScreenUpdating = False
    
    Set Newsh = ThisWorkbook.Sheets(Sheet20.Name)
    Newsh.Range("C12").CurrentRegion.Offset(1).Clear
    NR = 9
    
        
        For Each Sh In ThisWorkbook.Worksheets
            If Sh.Name <> Sheet1.Name And Sh.Name <> Sheet7.Name And Sh.Visible Then
                LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
                If LR > 8 Then
                    Sh.Range("B13:AJ" & LR).Copy
                    Newsh.Range("B13").PasteSpecial xlPasteValues 'Paste Destination
                    Newsh.Range("B13").PasteSpecial xlPasteValues 'Paste Destination
                    LR = Newsh.Range("B" & Rows.Count).End(xlUp).Row
                    NR = LR + 1
       
                End If
            End If
        Next Sh
        
    Application.ScreenUpdating = True
    
    End Sub
    thx u so much!

  4. #4
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    I cant view the file due to firewall, but try this

    Private Sub Worksheet_Activate()
    Dim Sh As Worksheet
    Dim Newsh As Worksheet
    Dim LR As Long, NR As Long
    
    Application.ScreenUpdating = False
    
    Set Newsh = ThisWorkbook.Sheets(20).Name
    Newsh.Range("C12").CurrentRegion.Offset(1).Clear
    NR = 9
    
        
        For Each Sh In ThisWorkbook.Worksheets
            If Sh.Name <> Sheets(1).Name And Sh.Name <> Sheets(7).Name And Sh.Visible Then
                LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
                If LR > 8 Then
                    Sh.Range("B13:AJ" & LR).Copy
                    Newsh.Range("B13").PasteSpecial xlPasteValues 'Paste Destination
                    Newsh.Range("B13").PasteSpecial xlPasteValues 'Paste Destination
                    LR = Newsh.Range("B" & Rows.Count).End(xlUp).Row
                    NR = LR + 1
       
                End If
            End If
        Next Sh
        
    Application.ScreenUpdating = True
    
    End Sub

  5. #5
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    hey im getting an error "object required" on this line

    Set Newsh = ThisWorkbook.Sheets(20).Name
    ur thoughts?

  6. #6
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    the newsh is the sheet object so it does not require the .name paramater

    try this

    Sub test()
    Dim Sh As Worksheet
    Dim Newsh As Worksheet
    Dim LR As Long, NR As Long
    
    Application.ScreenUpdating = False
    
    Set Newsh = ThisWorkbook.Sheets(20)
    Newsh.Range("C12").CurrentRegion.Offset(1).Clear
    NR = 9
    
        
        For Each Sh In ThisWorkbook.Worksheets
            If Sh.Name <> Sheets(1).Name And Sh.Name <> Sheets(7).Name And Sh.Visible Then
                LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
                If LR > 8 Then
                    Sh.Range("B13:AJ" & LR).Copy
                    Newsh.Range("B13").PasteSpecial xlPasteValues 'Paste Destination
                    Newsh.Range("B13").PasteSpecial xlPasteValues 'Paste Destination
                    LR = Newsh.Range("B" & Rows.Count).End(xlUp).Row
                    NR = LR + 1
       
                End If
            End If
        Next Sh
        
    Application.ScreenUpdating = True
    
    End Sub

  7. #7
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    actually its notwrking at all now....when i paste the new code :S
    Last edited by jw01; 03-30-2012 at 10:05 AM.

  8. #8
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    could you include a sheet with sample data? i cannot access skydrive.

  9. #9
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    it's not uploading the file on this thread for some wierd reason :S

    i uploadd it onto google docs...u dont need to sign in...let me know if this works.

    https://docs.google.com/open?id=0B1Q...Rm5BRGVadUtadw

    thxs!
    Last edited by jw01; 03-30-2012 at 11:29 AM.

  10. #10
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    took a look and made a couple change, give this a run

    Private Sub Worksheet_Activate()
    Dim Sh As Worksheet
    Dim Newsh As Worksheet
    Dim LR As Long, NR As Long
    
    Application.ScreenUpdating = False
    
    Set Newsh = ThisWorkbook.Sheets(Sheet20.Name)
    Newsh.Range("C12").CurrentRegion.Offset(1).Clear
    NR = 13
    
        
        For Each Sh In ThisWorkbook.Worksheets
            If Sh.Name <> Sheet1.Name And Sh.Name <> Sheet7.Name And Sh.Name <> Sheet20.Name And Sh.Visible Then
                LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
                If LR > 8 Then
                    Sh.Range("C13:AJ" & LR).Copy
                    Newsh.Range("C" & NR).PasteSpecial xlPasteFormats 'Paste Destination
                    Newsh.Range("C" & NR).PasteSpecial xlPasteAll 'Paste Destination
                    NR = Newsh.Range("C" & Rows.Count).End(xlUp).Row + 1
       
                End If
            End If
        Next Sh
        
    Application.ScreenUpdating = True
    
    End Sub

  11. #11
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    omg thxu so much for your great help....i was confused...it appears this was the missing link "And Sh.Name <> Sheet20.Name"

    also...real quick...i have a formula in column B on the consolidation sheet
    if(C1="",0,1)
    where if 1...then i have a conditional format for the row to have a border ...else if 0 then no border....

    that part is not coming through...any idea why? thx u sir

  12. #12
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    this should take care of that

    Private Sub Worksheet_Activate()
    Dim Sh As Worksheet
    Dim Newsh As Worksheet
    Dim LR As Long, NR As Long
    
    Application.ScreenUpdating = False
    
    Set Newsh = ThisWorkbook.Sheets(Sheet20.Name)
    Newsh.Range("C12").CurrentRegion.Offset(1).Clear
    NR = 13
    
        
        For Each Sh In ThisWorkbook.Worksheets
            If Sh.Name <> Sheet1.Name And Sh.Name <> Sheet7.Name And Sh.Name <> Sheet20.Name And Sh.Visible Then
                LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
                If LR > 8 Then
                    Sh.Range("C13:AJ" & LR).Copy
                    Newsh.Range("C" & NR).PasteSpecial xlPasteFormats 'Paste Destination
                    Newsh.Range("C" & NR).PasteSpecial xlPasteAll 'Paste Destination
                    NR = Newsh.Range("C" & Rows.Count).End(xlUp).Row + 1
                End If
            End If
        Next Sh
        Newsh.Range("B1:B" & NR - 1).FormulaR1C1 = "=IF(RC[1]="""",0,1)"
        
    Application.ScreenUpdating = True
    
    End Sub

  13. #13
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    hello that works like a charm....thx u so much..it is much appreciated.

    once final request..or rather an issue that is showing...for some odd reason on my consoidation sheet, all the data is beng transfered but when the macro consolidates the data from the other workbooks, it is removing the "header fields" and all other text above row 13 on the "2012" consolidation sheet....any thoughts why?

    thx u once again for ur allstar help.

  14. #14
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    The macro was clearing it, i changed the clear portion to only clear the bottom of the file, not the headers

    Private Sub Worksheet_Activate()
    Dim Sh As Worksheet
    Dim Newsh As Worksheet
    Dim LR As Long, NR As Long
    
    Application.ScreenUpdating = False
    
    Set Newsh = ThisWorkbook.Sheets(Sheet20.Name)
    Newsh.Range("C13:AP100000").Clear
    NR = 13
    
        
        For Each Sh In ThisWorkbook.Worksheets
            If Sh.Name <> Sheet1.Name And Sh.Name <> Sheet7.Name And Sh.Name <> Sheet20.Name And Sh.Visible Then
                LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
                If LR > 8 Then
                    Sh.Range("C13:AJ" & LR).Copy
                    Newsh.Range("C" & NR).PasteSpecial xlPasteFormats 'Paste Destination
                    Newsh.Range("C" & NR).PasteSpecial xlPasteAll 'Paste Destination
                    NR = Newsh.Range("C" & Rows.Count).End(xlUp).Row + 1
                End If
            End If
        Next Sh
        Newsh.Range("B1:B" & NR - 1).FormulaR1C1 = "=IF(RC[1]="""",0,1)"
        
    Application.ScreenUpdating = True
    
    End Sub

  15. #15
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    hello

    thxs for your wonderful help..i really appreciate all your feedback...it works like a charm now.

    one query....i have the following macro filters ...however in my consolidation sheet, it does not filter by my criteria in cell C7 or named range "link"

    any idea why it is not sorting?

    Sub Filter_name()
        Dim c As Long
        
            Application.ScreenUpdating = False
        
        With Range("_Data").CurrentRegion
            .AutoFilter
            For c = 1 To .Columns.Count
                .AutoFilter Field:=c, VisibleDropDown:=False
            Next c
            .AutoFilter Field:=3, Criteria1:=Range("Link").Value, VisibleDropDown:=False
        End With
        
            Application.ScreenUpdating = False
        
        Range("Header") = "Filtered by: NAE Name"
        
    End Sub
    i truely appreciate your help sir.

  16. #16
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    you might need to open a new thread on this one, i dont know if ill be able to help with it till monday.

  17. #17
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    hello DGagnon,

    thank you for your helpand update. please let me know if you know what the issue maybe with the filter

    thx u sir!

  18. #18
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: macro consolidates data from worksheets - question

    hey dgagnon

    any thoughts you have on this? thx u sir

  19. #19
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: macro consolidates data from worksheets - question

    sorry i dont have much experiance with Filter via VBA, might be best to start a new topic and get one of the experts in on it.

+ 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