Solved

Excel Macro to Update Main Sheet

Posted on 2003-11-18
7
1,132 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 81

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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 81

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 81

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

807 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