+ Reply to Thread
Results 1 to 8 of 8

Copy Data from multiple sheets to Main datasheet

Hybrid View

bogleda Copy Data from multiple... 05-06-2014, 01:42 PM
xladept Re: Copy Data from multiple... 05-06-2014, 04:58 PM
bogleda Re: Copy Data from multiple... 05-07-2014, 10:28 AM
xladept Re: Copy Data from multiple... 05-07-2014, 05:42 PM
xladept Re: Copy Data from multiple... 05-07-2014, 03:19 PM
bogleda Re: Copy Data from multiple... 05-08-2014, 02:03 PM
xladept Re: Copy Data from multiple... 05-08-2014, 02:19 PM
xladept Re: Copy Data from multiple... 05-09-2014, 01:42 PM
  1. #1
    Registered User
    Join Date
    05-13-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    4

    Copy Data from multiple sheets to Main datasheet

    Hi, I am new to the forum and this is my first posting. I have only created a few simple (very simple) VBA codes in the past.

    I have a workbook that contains multiple sheets, currently five sheets of which only two of them are Info Datasheets.

    I would like to create a VBA code that pulls data from multiple info datasheets and compiles that data into one Main Database sheet. However, after that initial collection, I need the code to maintain the rows data. Specifically, if any row’s data changes in the info Datasheets I need that row on the main Database sheet to update.

    The columns in the info datasheets range from A:AH, however I only need the columns A:E to be copied. And I would like the code to add column F in the main datasheet displaying the sheet name were the data was retrieved

    Each Info sheet (Metals, Polymers) are setup identical;
    Rows 1:3 are the headers, and Column D and/or Column E will denote a change to the row.

    The Main Database sheet (Table of Context) has 2 rows for the header. So, the data will start on row 3

    F-S886 (Material Properties Database)_DRAFT_5.xls

    Any help would be greatly appreciated,
    Thank you
    Dave

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

    Re: Copy Data from multiple sheets to Main datasheet

    Hi Bogleda,

    Here's one to load your Table of Context:

    Sub Bogleda(): Dim wt As Worksheet, ws As Worksheet, t As Long, r As Long, i As Long, D
    Set wt = Sheets("Table of Context"): t = wt.Range("A" & Rows.Count).End(xlUp).row + 1
    For Each ws In Worksheets
    If ws.Name = wt.Name Or ws.Name = "CONVERSIONS" Or ws.Name = "DropDown Menus" Then GoTo GetNext
    r = 4: Do Until ws.Range("A" & r) = "": r = r + 1: Loop
    D = ws.Range(ws.Cells(4, 1), ws.Cells(r, 6)): r = r - 4
    For i = 1 To r: D(i, 6) = ws.Name: Next i
    wt.Range(wt.Cells(t, 1), wt.Cells(t + r, 6)) = D
    t = t + r
    GetNext: Next
    End Sub
    I'm thinking about the change event code now

    Here's a start! F-S886 (Material Properties Database).xls

    And - Welcome to the forum
    Last edited by xladept; 05-06-2014 at 05:51 PM.
    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

  3. #3
    Registered User
    Join Date
    05-13-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Copy Data from multiple sheets to Main datasheet

    Hello, xladept.

    Thank you. The copy code worked perfectly.

    The change code you are working on, will it also update the table
    of context when new data is entered into the info sheets? I have
    many more materials to add.

    Again, Thank you for your help.

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

    Re: Copy Data from multiple sheets to Main datasheet

    Hi Bogleda,

    Just in case you want to change the Number:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
                    Set Sh = ActiveSheet
    If Sh.Name = "Table of Context" Or Sh.Name = "CONVERSIONS" Or _
    Sh.Name = "DropDown Menus" Then Exit Sub
    If Target <> "" And Target.Column < 6 Then
    Dim wt As Worksheet, X As String, FN As String, F As Range, D, r As Long
    Set wt = Sheets("Table of Context"):  r = Target.Row: X = Cells(r, 1)
    If Target.Column = 1 Then X = Cells(r, 2)
    D = Range(Cells(r, 1), Cells(r, 6)): D(1, 6) = Sh.Name
    Set F = wt.Range("A:B").Find(X)
    If Not F Is Nothing Then
    Application.EnableEvents = False
    wt.Range(wt.Cells(F.Row, 1), wt.Cells(F.Row, 6)) = D
    Application.EnableEvents = True
    End If: End If: End Sub

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

    Re: Copy Data from multiple sheets to Main datasheet

    Hi Bogleda,

    The change code is included in the attachment - will the A column entry ever be changed?

    You're welcome and thanks for the rep!

  6. #6
    Registered User
    Join Date
    05-13-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Copy Data from multiple sheets to Main datasheet

    Hi, xladept.

    No, the number will never change. The number is the controlling body for that specific material type. Once the Row is added to the Info datasheet, it will never be deleted.

    I notice the columns are now numbered. Could they be changed back to letters?
    If not, no big deal. I can update my supporting SOPs accordingly.

    I will need to add to the materials list on the info datasheets. However, I just added a few more on the metals sheet, but the new items did not show up on the table of context sheet. I tried re-running the copy code; this just adds the entire metals sheet data to the bottom of what was already on the Table of Context sheet.

    Also, I will most likely need, in the future, to add new Sheets for Isotropic-Hyperelastic, Isotropic-Elastoplastic, Orthotropic, and Transversely-Isotropic materials.

    To sum up:
    Can I add line items (Rows) to the existing info datasheets that will copy over to the TOC?
    Can the conditional formatting be copied with the data to the TOC?
    Can I add info datasheets to the workbook and would they be included with the copy code?


    Ps. do you have any recommendations on books that will help me understand VBA code and how to develop VBA codes?
    a.k.a VBA Code for dummies


    Thank you, again for all your help.
    Dave

  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: Copy Data from multiple sheets to Main datasheet

    Hi Bogleda,

    Can I add line items (Rows) to the existing info datasheets that will copy over to the TOC?

    Can I add info datasheets to the workbook and would they be included with the copy code?
    You'd have to disable events and rerun the :Bogleda for that

    Can the conditional formatting be copied with the data to the TOC?
    The program would have to be rewritten to transfer the Conditional Formatting

    I used "Writing Excel Macros" - O'Reilly by Steven Roman
    and I bought "Excel 2003 Power Programming with VBA" by John Walkenbach.

    But we have a Tips and Tutorials Forum with many good suggestions
    Last edited by xladept; 05-08-2014 at 03:52 PM.

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

    Re: Copy Data from multiple sheets to Main datasheet

    Hi Bogleda,

    This should get your CF:

    Sub Bogleda2(): Dim wt As Worksheet, ws As Worksheet, t As Long, r As Long, i As Long, D As Range
    Application.EnableEvents = False: t = 3: Set wt = Sheets("Table of Context"): wt.Activate
    wt.Range(Cells(t, 1), wt.Cells(Rows.Count - t, 1)).EntireRow.Clear
    For Each ws In Worksheets
    If ws.Name = wt.Name Or ws.Name = "CONVERSIONS" Or ws.Name = "DropDown Menus" Then GoTo GetNext
    r = 4: Do Until ws.Range("A" & r) = "": r = r + 1: Loop: r = r - 1
    For i = 4 To r: ws.Cells(r, 6) = ws.Name: Next i
    Set D = ws.Range(ws.Cells(4, 1), ws.Cells(r, 6)): r = r - 3
    D.Copy wt.Range("A" & t)
    t = t + r: wt.Columns.AutoFit: wt.Rows.AutoFit
    GetNext: Next: Application.EnableEvents = True: End Sub
    And - when you're building the full book, you could just Change the name of the event code in the ThisWorkbook module:

    Private Sub XWorkbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
                    Set Sh = ActiveSheet
    If Sh.Name = "Table of Context" Or Sh.Name = "CONVERSIONS" Or _
    Sh.Name = "DropDown Menus" Then Exit Sub
    If Target <> "" And Target.Column < 6 Then
    Dim wt As Worksheet, X As String, FN As String, F As Range, D, r As Long
    Set wt = Sheets("Table of Context"):  r = Target.Row: X = Cells(r, 1)
    If Target.Column = 1 Then X = Cells(r, 2)
    D = Range(Cells(r, 1), Cells(r, 6)): D(1, 6) = Sh.Name
    Set F = wt.Range("A:B").Find(X)
    If Not F Is Nothing Then
    Application.EnableEvents = False
    wt.Range(wt.Cells(F.Row, 1), wt.Cells(F.Row, 6)) = D
    Application.EnableEvents = True
    End If: End If: End Sub
    Last edited by xladept; 05-09-2014 at 02:43 PM.

+ 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. Copy data from multiple sheets to one main based on cell value
    By jdjenterprises in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-28-2013, 10:13 PM
  2. Replies: 2
    Last Post: 02-06-2013, 11:25 AM
  3. [SOLVED] Macro to get/copy data from multiple secondary sheets to main sheet
    By CaatalyyN616 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-29-2012, 04:22 AM
  4. copy data from main sheet to respective sub sheets
    By sshanku1985 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-14-2011, 12:26 PM
  5. Copy Varying Range Sizes from Multiple Sheets to Main Sheet
    By Wester in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2010, 03:12 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