+ Reply to Thread
Results 1 to 12 of 12

Specify sheets for data extract

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    Specify sheets for data extract

    Hi Folks,

    Following a work laptop refresh I've lost the LET and VSTACK functions and am unlikely to get it back until our IT Department decides to update (whenever that may be).

    Therefore, I'm trying to come up with a solution to achieve the extraction of data from several sheets in to one. A search on the web has provided me with this VBA solution from Data Cycle Analytics which goes some way to helping me achieve my objective. However, rather than looping through all sheets, As it will ultimately be part of a much bigger workbook, I want to be able to specify the names of the sheets where the data will be extracted from.

    For example. Where it says "If Left(sht.name, 1) = 4 Then". I want to be able to provide the actual sheet name(s) (e.g. I only want to extract data from sheets "4R Class" and "4Y Class").

    I'm looking for help with the code to help me specify the sheet names.

    Please Login or Register  to view this content.
    Thanks in advance
    Attached Files Attached Files
    Last edited by 6StringJazzer; 03-03-2024 at 08:42 AM. Reason: Streamlined title. All posts are requests for help.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Specify sheets for data extract

    You can replace that line with something like this:
    Please Login or Register  to view this content.
    Or as an If statement if you're more comfortable with that:
    Please Login or Register  to view this content.
    Or if you have lots of sheet names you want to perform actions on then you could put them in a table somewhere in the workbook and when you're looping through the sheets just test if the sheet name appears in that table.

    BSB

  3. #3
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    Re: Specify sheets for data extract

    Hi BSB,

    In a stand alone workbook that worked brilliant and rep added. However, when transferred to my live workbook, it's highlighted a different issue. The "real world" values in the source sheets are set through formula and it's that formula that is being copied. Can you think of a way to adjust my code so that it pastes values.

    Also, I think that because it's formula it's copy all 500 rows per sheet. So is there a way of adding in a criteria that if the value of a cell = "" then don't copy?

    Thanks

    MM

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Specify sheets for data extract

    You can certainly have code that will paste values and you can certainly have it only copy a "used range", i.e. ignore any rows where the formulas return a nil value.

    To adjust the code it would be helpful to see what the real data looks like. Do the formulas on the unused rows leave the cells blank, or show a zero, or show an error code?
    Also would the data have blank rows in the middle? i.e. would there be a student #13 then #14 is blank but #15 is populated?

    BSB

  5. #5
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    Re: Specify sheets for data extract

    Thanks BSB,

    I can definitely confirm there won't be any blank rows in the middle of each source sheet.

    I'll try an mock it up so it presents as a formula and attach. (It's actually an aggregate formula but I'll do my best to create something).

    EDIT: Mock up attached. With an additional tab that shows my 'Desired output' (It's not the true 'real world' formula in the as, in reality, the source sheets are populated through a series of aggregated formula - I can't provide that due to confidentiality reasons)

    FYI, the objective will then be to export it as a *.csv so the data can be uploaded to a different system. But I've got that bit covered
    Attached Files Attached Files
    Last edited by MagicMan; 03-03-2024 at 11:44 AM. Reason: Attachment of mock up file

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Specify sheets for data extract

    Quote Originally Posted by MagicMan View Post
    I'll try an mock it up so it presents as a formula and attach. (It's actually an aggregate formula but I'll do my best to create something).
    As long as I know what the formulas in the unused rows show as a result then that's all I'd need to amend the code you have.
    The process will be slightly different based on the results.

    BSB

  7. #7
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    Re: Specify sheets for data extract

    Thanks BSB, previous post amended.

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Specify sheets for data extract

    Try this:
    Please Login or Register  to view this content.
    I've commented out some of the Dim lines that aren't required with this approach.

    BSB

  9. #9
    Registered User
    Join Date
    12-05-2023
    Location
    France
    MS-Off Ver
    Office 365
    Posts
    7

    Re: Specify sheets for data extract

    Hello everybody (I'm french, and not english frendly)

    Accordingly with BadlySpelledBuoy "it would be helpful to see what the real data looks like."
    When there is no data to control the process, it's difficult.

    This Is not the solution : To control a list of sheets i use an array which list the only items allowed (IsStringInArray) rather to use "Select case" or multiple "If"
    I found many constants in the original subroutine which annoying me to check the process.

    BadlySpelledBuoy
    I dont understand where you got these sheet names
    If sht.Name = "GDPR SF Extract" Or sht.Name = "DSE Trg SF Extract" Or sht.Name = "DSE *** SF Extract" Or sht.Name = "CSA SF Extract" Then
    The above function can be called like this

    if IsStrInArray(sht.Name, 1, Array("GDPR SF Extract","DSE Trg SF Extract","DSE *** SF Extract","CSA SF Extract") Then

    Function IsStringInArray(str, iStart, arr)
    i = iStart
    IsStringInArray = False
    Do
    If i <= UBound(arr) Then
    If LCase(arr(i)) Like LCase(str) Then IsStringInArray = True: Exit Do
    End If
    i = i + 1
    Loop Until i = UBound(arr) + 1
    End Function

  10. #10
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428
    BSB...

    That's bang on! Thank you 😊

    Takes a little while in my real life work book, but there's significantly more sheets for it to process.

    Thank you SOOO MUCH!

    Virtual case of beer on its way.

    MM

  11. #11
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Specify sheets for data extract

    You're more than welcome! Glad I could help

    I shall look forward to the virtual beers because my virtual drinks cabinet is currently bare!

    Good luck with the project and give us a shout if you need more help.

    BSB

  12. #12
    Registered User
    Join Date
    12-05-2023
    Location
    France
    MS-Off Ver
    Office 365
    Posts
    7

    Re: Specify sheets for data extract

    Sorry, i dont saw your data and the solution of BadlySpelledBuoy is fine.

+ 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. [SOLVED] Extract data from multiple sheets to multiple sheets based on date(today)
    By KalilMe in forum Excel Programming / VBA / Macros
    Replies: 63
    Last Post: 08-02-2023, 11:00 AM
  2. [SOLVED] Extract data from multiple sheets to one sheet based on sheets names
    By Maklil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2023, 01:56 PM
  3. [SOLVED] Extract Data from Sheets
    By jebindavidson in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 10-03-2022, 08:34 PM
  4. [SOLVED] How to extract associated data from different sheets?
    By peterhan99101 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-10-2022, 04:10 AM
  5. sheets add and extract data to different from master
    By dorabajji in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-27-2019, 11:40 AM
  6. Extract data from Sheet 1 to several sheets
    By ECEUK in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-05-2015, 02:22 PM
  7. Replies: 3
    Last Post: 12-02-2005, 08:10 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