Solved

Excel Macro to Update Main Sheet

Posted on 2003-11-18
7
1,129 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:mbean
  • 3
  • 3
7 Comments
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9774864
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.
0
 

Author Comment

by:mbean
ID: 9774980
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  
0
 
LVL 80

Expert Comment

by:byundt
ID: 9775103
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
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:mbean
ID: 9780852
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
0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
ID: 9780953
Mary,
To skip over multiple worksheets, it is better to use a Select Case construction. The following sub ignores Bulb_list, Projectors and Returns:

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
    Select Case ws.Name
    Case "Bulb_list", "Projectors","Returns"
    Case Else
        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 Select
Next ws
End Sub

Brad
0
 

Author Comment

by:mbean
ID: 9781089
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!!!
0
 
LVL 80

Expert Comment

by:byundt
ID: 9781516
Mary,
Thanks for the grade!
Brad
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: dandraka
There are several quick shortcuts that can make your life easier in Microsoft Programs.  These simple tips and tricks will your work more productive and you faster at completing your tasks! MS Word (1) Creating Re-usable Scraps You can create s…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now