Link to home
Start Free TrialLog in
Avatar of mbean
mbean

asked on

Excel Macro to Update Main Sheet

I have an Excel Workbook that has multiple worksheets that I use to track the status of projector bulbs that we use.  There is a separate worksheet for each bulb (For example 0120, 0736, 0754, etc.), and a main sheet called Bulb List that I need to update with the last record from each of the individual bulb worksheets.  I would like the macro to loop through each of the worksheets and update the main sheet with the latest info from the individual worksheets.

I have been written the following code to get started but would like it to loop through all the individual worksheets without me having to name them since the main bulb list already has over 50 bulbs and continues to grow.

Sub Build_Current_Status()
'
' Build_Current_Status Macro
' Macro recorded 11/6/2003 by tmoore
'

'
    Range("C2").Select
   
    Application.Goto Reference:=Worksheets("0120").Range("B1")
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Bulb_list").Select
    ActiveSheet.Paste
   
    Range("C3").Select
    Application.Goto Reference:=Worksheets("0736").Range("B1")
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Bulb_list").Select
    ActiveSheet.Paste
   
    Range("C4").Select
    Application.Goto Reference:=Worksheets("0754").Range("B1")
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Bulb_list").Select
    ActiveSheet.Paste
   
    Range("C5").Select
    Application.Goto Reference:=Worksheets("0792").Range("B1")
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Bulb_list").Select
    ActiveSheet.Paste
End Sub

Thanks for any help,

mbean
Avatar of Anne Troy
Anne Troy
Flag of United States of America image

If it were me....

I would make all my worksheets have Row 1 contain the TOTALS [i.e., =sum(B3:B65536)] and Row 2 contain the titles.

Then, you could easily use formulas on your summary worksheet instead of using code.
Avatar of mbean
mbean

ASKER

Let me explain a little more:

The individual bulb worksheets (0120, 0736, 0744, etc.) have the following columns:

Date, From Location, To Location, Hours, Notes or Actions Taken

Each of the individual bulb worksheets (0120, 0736, 0744, etc.) over time will have several rows of data (records).  

My Summary Worksheet (Bulb List) has the same columns as the individual bulb worksheets and I need to pull in the last row of data from each individual bulb worksheet. I also need to be able to undate the Summary Worksheet on a daily basis so I have the most current information. I need to clear the data on the Summary Worksheet prior to updating it with the most current info from the individual bulb worksheets.

Thanks  
Hi mbean,
The following macro pulls data from columns B to end of data from the last row on each worksheet. The results are pasted starting in row 2 of worksheet Bulb_list

Sub Build_Current_Status()
Dim ws As Worksheet, wsMaster As Worksheet
Dim rw As Range
Dim i As Long
Set wsMaster = Worksheets("Bulb_list")
i = 1
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Bulb_list" Then
        i = i + 1
        Set rw = ws.Cells(1, 2).End(xlDown)
        Set rw = Range(rw, rw.End(xlToRight))
        rw.Copy
        wsMaster.Cells(i, 1).PasteSpecial
    End If
Next ws
End Sub

Cheers!

Brad
Avatar of mbean

ASKER

Ok Brad...this works great now one more twist I have two worksheets that I do not want to include data from.  The following is a list of the worksheets in the workbook:

Bulb_List
Projectors
Returns
0120
0736
0744
etc.

I need to skip over Projectors & Returns but include all the other worksheets.

Thanks,

Mary
ASKER CERTIFIED SOLUTION
Avatar of byundt
byundt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mbean

ASKER

Brad,

Thanks...that did the trick.  I had to modify it slightly to only paste values so here it is with the modifications:

Sub BuildCurrentStatus()
Dim ws As Worksheet, wsMaster As Worksheet
Dim rw As Range
Dim i As Long
Set wsMaster = Worksheets("Bulb_list")
i = 1
For Each ws In ActiveWorkbook.Worksheets
    Select Case ws.Name
    Case "Bulb_list", "Projectors", "Returns"
    Case Else
        i = i + 1
        Set rw = ws.Cells(1, 1).End(xlDown)
        Set rw = Range(rw, rw.End(xlToRight))
        rw.Copy
        wsMaster.Cells(i, 1).PasteSpecial xlPasteValues
    End Select
Next ws
End Sub

Thanks Again!!!
Mary,
Thanks for the grade!
Brad