Results 1 to 2 of 2

Pull data from multiple sheets macro

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    04-21-2005
    Location
    Southern England
    MS-Off Ver
    Excel for Office 365
    Posts
    1,702

    Pull data from multiple sheets macro

    Hi,

    I was previously helped with a macro which would return data from sheets 1-6 if the row contained data (if it didn’t it was ignored).

    Currently it is set up to pull data for only three months. This is defined by cells E5:G5 on the upload sheet e.g. if period 1 is in cell E5 then it would pull the rows which contain data on sheets 1 to 6 in the period 1 column.

    I now need the macro below amended so that it pulls 12 months rather than 3 – how would it be ameneded?


    Sub UploadData()
    Dim TR, LR, LC1, LC2, LC3, Sum1, Sum2, Sum3, Wrow As Long
    Dim Sh
    Dim K As String
    
    On Error Resume Next
    
    LC1 = Sheets("1").Cells.Find(Sheets("Upload").Range("E5").Value).Column
    LC2 = Sheets("1").Cells.Find(Sheets("Upload").Range("F5").Value).Column
    LC3 = Sheets("1").Cells.Find(Sheets("Upload").Range("G5").Value).Column
    Wrow = 6
    
    For TR = 6 To 277
        
        For Each Sh In Worksheets
     If Sh.Cells(TR, "A") <> "" And Sh.Cells(TR, "G") <> "" Then
           If Sh.Name <> "Upload" And Sh.Name <> "Summary" Then
            Sum1 = Sh.Cells(TR, LC1).Value
            Sum2 = Sh.Cells(TR, LC2).Value
            Sum3 = Sh.Cells(TR, LC3).Value
            End If
        
        If Sum1 + Sum2 + Sum3 > 0 Then
            If Sum1 > 0 Then Sheets("Upload").Cells(Wrow, "E") = Sum1
            If Sum2 > 0 Then Sheets("Upload").Cells(Wrow, "F") = Sum2
            If Sum3 > 0 Then Sheets("Upload").Cells(Wrow, "G") = Sum3
        Sheets("Upload").Cells(Wrow, "B") = Sh.Cells(TR, "A")
        Sheets("Upload").Cells(Wrow, "C") = Sh.Cells(TR, "G")
        
        K = Trim(Sh.Cells(TR, "I"))
        Sheets("Upload").Cells(Wrow, "D") = Right(K, Len(K) - 7)
        Wrow = Wrow + 1
        K = ""
        End If
     End If
       
        Next Sh
        
        
    Next TR
    End Sub
    Attached Files Attached Files

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