Results 1 to 10 of 10

Using a User Form to pull data from multiple sheets into main sheet

Threaded View

  1. #1
    Registered User
    Join Date
    07-24-2018
    Location
    California
    MS-Off Ver
    10
    Posts
    56

    Talking Using a User Form to pull data from multiple sheets into main sheet

    Okay bear with me, this might be a confusing/long question but I would SUPER appreciate any help...

    I have an excel workbook that contains multiple sheets of data, one for each Product (Product A, B, C, D...) in which each sheet has a table of information, and a Main sheet that I would like to display different information in.

    In each sheet, the table of data includes Column A (Item#), Column B (Quantity), Column C (Quantity * 1), Column D (Quantity * 2),
    and Column E (Quantity * 3)

    I have created a User Form in the Main sheet that allows user to select which Product (Product A, B, C, D...) and what number of Lots to produce (1, 2, 3) they would like to see data for using drop down boxes.

    SO, I would like to create a macro that, when a user chooses the Product and #, will pull all the correct data from the corresponding tabs and populate it in a blank table located in the Main sheet

    I am not super well versed in VBA so in trying to figure out this code, I started to just write out the logic from my head in a way that hopefully other people understand what I'm trying to accomplish and be able to help with... here goes nothing:

    Private Sub CreateBOM_Click()
    
    Dim lngRow As Long
    Worksheets("Master BOM").Activate
    lngRow = Worksheets("Master BOM").Range("B1048576").End(xlUp).Row + 1
    
    'Based off what options you chose, excel will grab the correct data from the corresponding product tabs
    
    If ProductName = "A" & NumberLots = 1 Then
        Cells(lngRow, 1) = Worksheets("A").Table("ProductA").Column("A")
        Cells(lngRow, 2) = Worksheets("A").Table("ProductA").Column("B")
        Cells(lngRow, 3) = Worksheets("A").Table("ProductA").Column("C")   'C would be quantity * 1
        
    If ProductName = "A" & NumberLots = 2 Then
        Cells(lngRow, 1) = Worksheets("A").Table("ProductA").Column("A")
        Cells(lngRow, 2) = Worksheets("A").Table("ProductA").Column("B")
        Cells(lngRow, 3) = Worksheets("A").Table("ProductA").Column("D")   'D would be quantity * 2
        
    If ProductName = "A" & NumberLots = 3 Then
        Cells(lngRow, 1) = Worksheets("A").Table("ProductA").Column("A")
        Cells(lngRow, 2) = Worksheets("A").Table("ProductA").Column("B")
        Cells(lngRow, 3) = Worksheets("A").Table("ProductA").Column("E")  'E would be quantity * 3
     
    If ProductName = "B" & NumberLots = 1 Then
        Cells(lngRow, 1) = Worksheets("A").Table("ProductB").Column("A")
        Cells(lngRow, 2) = Worksheets("A").Table("ProductB").Column("B")
        Cells(lngRow, 3) = Worksheets("A").Table("ProductB").Column("C")   'C would be quantity * 1
        
    If ProductName = "B" & NumberLots = 2 Then
        Cells(lngRow, 1) = Worksheets("A").Table("ProductB").Column("A")
        Cells(lngRow, 2) = Worksheets("A").Table("ProductB").Column("B")
        Cells(lngRow, 3) = Worksheets("A").Table("ProductB").Column("D")   'D would be quantity * 2
        
    If ProductName = "B" & NumberLots = 3 Then
        Cells(lngRow, 1) = Worksheets("A").Table("ProductB").Column("A")
        Cells(lngRow, 2) = Worksheets("A").Table("ProductB").Column("B")
        Cells(lngRow, 3) = Worksheets("A").Table("ProductB").Column("E")  'E would be quantity * 3
    
    '...etc 
    
    End If


    I know there MUST be an easier/more efficient way of writing this, so if you have any ideas or need more context please please let me know!

    Thank you so much!
    Attached Files Attached Files
    Last edited by sy898661; 05-31-2019 at 05:05 PM. Reason: adding code tags and attaching file

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Matching Multiple sheets data to a main sheet
    By Ryan29 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-05-2016, 10:21 AM
  2. Populate data from one main sheet to multiple sheets
    By robi0342 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2016, 10:16 PM
  3. Populate data from one main sheet to multiple sheets
    By robi0342 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-23-2016, 09:19 PM
  4. Pull data from multiple sheets based on cell in Main sheet
    By cpyter in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-29-2014, 01:19 PM
  5. Macro code to pull the data from different sheets to main sheet
    By Shanthuday in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2012, 09:54 AM
  6. Macro code to pull data from different sheets based on the header of the main sheet
    By Shanthuday in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-21-2012, 05:00 AM
  7. Replies: 0
    Last Post: 01-23-2012, 02:49 PM

Tags for this Thread

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