Solved

Excel Macro to Update Main Sheet

Posted on 2003-11-18
7
1,135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

615 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