+ Reply to Thread
Results 1 to 11 of 11

Edit VBA code to get data from multiple sheets

Hybrid View

leprince2007 Edit VBA code to get data... 12-25-2016, 12:25 PM
mike7952 Re: Edit VBA code to get data... 12-25-2016, 01:39 PM
xladept Re: Edit VBA code to get data... 12-25-2016, 01:44 PM
MarvinP Re: Edit VBA code to get data... 12-25-2016, 02:26 PM
leprince2007 thank you Mr. MarvinP.could... 12-25-2016, 06:14 PM
leprince2007 thank you Mr. MarvinP.could... 12-26-2016, 04:06 PM
xladept Re: Edit VBA code to get data... 12-26-2016, 04:14 PM
leprince2007 You code is great.but can you... 12-26-2016, 05:53 PM
mike7952 Re: Edit VBA code to get data... 12-26-2016, 06:50 PM
xladept Re: Edit VBA code to get data... 12-26-2016, 09:12 PM
leprince2007 Re: Edit VBA code to get data... 12-27-2016, 02:23 AM
  1. #1
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    774

    Edit VBA code to get data from multiple sheets

    Hello everybody
    The report indicates the lectures that the student "A" had from multiple sheets by using VBA code.
    I want to edit the vba code to include "Shift" ,it can be brought from other sheets from row No. 1
    Please your support
    Attached Files Attached Files
    Last edited by leprince2007; 12-25-2016 at 12:49 PM.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Edit VBA code to get data from multiple sheets

    This should do it

    Sub summary_code()
        Dim ws As Worksheet, myName, a, i As Long, ii As Long, x, w
        With Sheets("Report")
            '.Range("a15").CurrentRegion.Offset(, 1).ClearContents
           .Range("B15", "WWW20").ClearContents
        '.Range("J2", "K6").ClearContents
            myName = .Range("b2").Value
        End With
        ReDim w(1 To 6, 1 To 1)
        w(1, 1) = "Sheet Name": w(2, 1) = "Count": w(3, 1) = "Lecturer": w(4, 1) = "Lectures": w(5, 1) = "Date"
        For Each ws In Worksheets
            If ws.Name <> "Report" Then
                x = Application.Match(myName, ws.Columns(2), 0)
                If IsNumeric(x) Then
                    a = ws.Cells(1).CurrentRegion.Value
                    For ii = 3 To UBound(a, 2)
                        If a(x, ii) <> "" Then
                            ReDim Preserve w(1 To UBound(w, 1), 1 To UBound(w, 2) + 1)
                            w(1, UBound(w, 2)) = ws.Name
                            w(2, UBound(w, 2)) = IIf(w(1, UBound(w, 2) - 1) <> ws.Name, 1, Val(w(2, UBound(w, 2) - 1)) + 1)
                            w(3, UBound(w, 2)) = a(2, ii): w(4, UBound(w, 2)) = a(3, ii): w(5, UBound(w, 2)) = a(x, ii)
                            w(6, UBound(w, 2)) = a(1, ii)
                        End If
                    Next
                End If
            End If
        Next
        Sheets("Report").Range("a15").Resize(6, UBound(w, 2)).Value = w
    End Sub
    Last edited by mike7952; 12-25-2016 at 01:47 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Edit VBA code to get data from multiple sheets

    Hi leprince

    Try this:

    Sub summary_code()
        Dim ws As Worksheet, myName, a, i As Long, ii As Long, x, w
        With Sheets("Report")
            '.Range("a15").CurrentRegion.Offset(, 1).ClearContents
           .Range("A15", "WWW20").ClearContents
        '.Range("J2", "K6").ClearContents
            myName = .Range("b2").Value
        End With
        ReDim w(1 To 6, 1 To 1)
        w(1, 1) = "Sheet Name": w(2, 1) = "Count": w(3, 1) = "Lecturer": w(4, 1) = "Lectures"
        w(5, 1) = "Date": w(6, 1) = "Shift"
        For Each ws In Worksheets
            If ws.Name <> "Report" Then
                x = Application.Match(myName, ws.Columns(2), 0)
                If IsNumeric(x) Then
                    a = ws.Cells(1).CurrentRegion.Value
                    For ii = 3 To UBound(a, 2)
                        If a(x, ii) <> "" Then
                            ReDim Preserve w(1 To UBound(w, 1), 1 To UBound(w, 2) + 1)
                            w(1, UBound(w, 2)) = ws.Name
                            w(2, UBound(w, 2)) = IIf(w(1, UBound(w, 2) - 1) <> ws.Name, 1, Val(w(2, UBound(w, 2) - 1)) + 1)
                            w(3, UBound(w, 2)) = a(2, ii): w(4, UBound(w, 2)) = a(3, ii): w(5, UBound(w, 2)) = a(x, ii)
                            w(6, UBound(w, 2)) = a(1, ii)
                             
                        End If
                    Next
                End If
            End If
        Next
        Sheets("Report").Range("a15").Resize(6, UBound(w, 2)).Value = w
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,378

    Re: Edit VBA code to get data from multiple sheets

    Hello leprince,

    Excel has a newer tool called Power Query that is included in 2016 Excel and is an Add-In for 2010 and 2013 Excel. Your problem*can be solved using this tool, without needing any VBA code.
    See https://www.microsoft.com/en-us/down...3-73acbf6aa147 for installing the add in.

    Then look at my attached workbook, where I've taken your data and used*the tool on it. I've created a Connection Only to each sheet and then used PQ to Append all of them into a single table on Sheet1. PQ also has a tool called UnPivot, which I did with your data so I could do a Pivot Table with the data. I think my result is what you want. If you need the Lecturer's name that can be included above the topic name using a HLookup from any of the other sheets.

    PQ for leprince.xlsm

    I did your problem in about 5 minutes without needing to write any VBA code.*
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    774
    Quote Originally Posted by MarvinP View Post
    Hello leprince,

    Excel has a newer tool called Power Query that is included in 2016 Excel and is an Add-In for 2010 and 2013 Excel. Your problem*can be solved using this tool, without needing any VBA code.
    See https://www.microsoft.com/en-us/down...3-73acbf6aa147 for installing the add in.

    Then look at my attached workbook, where I've taken your data and used*the tool on it. I've created a Connection Only to each sheet and then used PQ to Append all of them into a single table on Sheet1. PQ also has a tool called UnPivot, which I did with your data so I could do a Pivot Table with the data. I think my result is what you want. If you need the Lecturer's name that can be included above the topic name using a HLookup from any of the other sheets.

    Attachment 494748

    I did your problem in about 5 minutes without needing to write any VBA code.*
    thank you Mr. MarvinP.could you please record a video to show me steps for dealing with power query in order to solve my problem??
    Last edited by leprince2007; 12-25-2016 at 06:17 PM.

  6. #6
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    774
    Quote Originally Posted by MarvinP View Post
    Hello leprince,

    Excel has a newer tool called Power Query that is included in 2016 Excel and is an Add-In for 2010 and 2013 Excel. Your problem*can be solved using this tool, without needing any VBA code.
    See https://www.microsoft.com/en-us/down...3-73acbf6aa147 for installing the add in.

    Then look at my attached workbook, where I've taken your data and used*the tool on it. I've created a Connection Only to each sheet and then used PQ to Append all of them into a single table on Sheet1. PQ also has a tool called UnPivot, which I did with your data so I could do a Pivot Table with the data. I think my result is what you want. If you need the Lecturer's name that can be included above the topic name using a HLookup from any of the other sheets.

    Attachment 494748

    I did your problem in about 5 minutes without needing to write any VBA code.*
    thank you Mr. MarvinP.could you please record a video to show me steps for dealing with power query in order to solve my problem??

    I tried to unpivot my table but -as my table has 2 rows in the header- PQ merges them in one column.
    Please help me

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Edit VBA code to get data from multiple sheets

    Wow, uncanny - Mike 7952 and I both posted nearly exact code maintenance - Mike's wasn't showing when I posted BTW!

  8. #8
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    774
    Quote Originally Posted by xladept View Post
    Wow, uncanny - Mike 7952 and I both posted nearly exact code maintenance - Mike's wasn't showing when I posted BTW!
    You code is great.but can you help me in using power query?.

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Edit VBA code to get data from multiple sheets

    @leprince2007.

    I don't use power query so, can't offer any help here.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Edit VBA code to get data from multiple sheets

    @leprince - me neither.

  11. #11
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    774

    Re: Edit VBA code to get data from multiple sheets

    Thank you both Mr.mike7952 and Mr.xladept
    I think Mr.MarvinP uses power query.Can you help me?

+ 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. Vba code to get data from multiple sheets
    By leprince2007 in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 12-06-2016, 03:00 AM
  2. How do I source and initialize data from multiple sheets with one VBA code?
    By mbizavin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-28-2014, 04:55 PM
  3. Use multiple sheets to display and edit data?
    By kenkay in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-27-2013, 01:37 PM
  4. Edit Multiple Sheets at Once
    By nguyeda in forum Excel General
    Replies: 1
    Last Post: 02-20-2009, 01:35 AM
  5. [SOLVED] Edit code - exclude sheets
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-15-2006, 11:40 AM
  6. [SOLVED] Edit code - exclude sheets
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-13-2006, 12:50 PM
  7. Edit code - exclude sheets
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-13-2006, 12:45 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