Consulting

Results 1 to 7 of 7

Thread: Updating multiple worksheets at once; four source, three target

  1. #1

    Updating multiple worksheets at once; four source, three target

    Dear all,

    Please see the file attached (there are the same columns on all sheets, apart from on "BLANK"). The "Sort" sheets 1-4 contain rows that appear at various places on the three "Raw data" sheets. The "Sort" sheets are mutually exclusive; there is no repetition of data among them.

    When I make an entry into the "ACTION" or "REASON" columns on any of the "Sort" sheets, I want that entry to be replicated on all relevant rows throughout the "Raw data" sheets. Matching of the rows is to be via Criteria 1 and 2.

    I would preferably like the replication to be as I make the entries (is this possible), but could also hit an update button periodically.

    I am a very much a beginner in these matters. What is the best approach here - to group the sheets, VLOOKUP, pivot tables, etc? How straightforward will this macro be? Has anyone any magic routines in their libraries to hand?

    Thanks in advance for any help that can be offered.

  2. #2

    Re: Updating multiple worksheets at once; four source, three target

    Sorry, the title should read: "... three target"

    I am currently looking into writing a private sub for each of the "Source" worksheets. This would activate when a change was made to that sheet's ACTION and/or REASON columns, group that sheet with the three "Raw data" ones and make the changes to the relevant cells (assuming this is possible). Or the macro could just loop through the rows of the three "Raw data" sheets and copy IF.

    Does this sound like the way forward or am I barking up the wrong tree? Or is my data structured badly in the workbook from the outset?

    Any inspiration would be very gratefully received. Many thanks again.
    Last edited by mdmackillop; 11-02-2006 at 03:15 PM. Reason: Title changed

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Or the macro could just loop through the rows of the three "Raw data" sheets
    Correct approach but use Find rather than loop which needs to check each cell. It's a lot quicker.

    Worksheet code
    [vba]
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column < 3 Then
    Application.EnableEvents = False
    FillData Target
    Application.EnableEvents = True
    End If
    End Sub

    [/vba]
    Module code
    [vba]
    Option Explicit
    Sub FillData(Target As Range)
    Dim Crit1 As String, Crit2 As String
    Dim FirstAddress As String
    Dim i As Long, Col As Long
    Dim c As Range
    Crit1 = Cells(Target.Row, 3)
    Crit2 = Cells(Target.Row, 4)
    Col = Target.Column
    For i = 1 To 3
    FirstAddress = ""
    With Worksheets(i).Columns(3)
    Set c = .Find(Crit1, LookIn:=xlValues, MatchCase:=True)
    If Not c Is Nothing Then
    FirstAddress = c.Address
    Do
    If c.Offset(, 1) = Crit2 Then Sheets(i).Cells(c.Row, Col) = Target
    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> FirstAddress
    End If
    End With
    Next
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Wow, that is pure genius and would have taken me about three months from where I am now! Thank you very much indeed, mdmackillop.

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    It seems that way at the start!
    Always remember that all this VBA code comes down to a series of simple steps, and the the VBA Help file does give a lot of assistance. In this case, the whole of the Find routine was copied from Help; I added in the bit to check the adjoining cell and the bit to loop three worksheets. Triggering it from the worksheets is a little more "advanced", but as you see, is very basic code.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6

    Update different workbook from active worksheet

    mdmackillop,

    I have a similar problem and I need your help too please.

    My source and target are different workbooks. When I update the cost of an item in source.xls (12 sheets), I'd like the new cost to be reflected anywhere that item is found in target.xls (26 sheets).

    The sheets in both workbooks have the following setup:

    ColA = Qty
    ColB = PartNum
    ColC = PartDesc
    ColD = UnitMeasurement
    ColE = UnitMaterialCost
    ColF = UnitLaborCost
    ColG = UnitEquipCost
    ColH = ExtMaterialCost
    ColI = ExtLabor Cost
    ColJ = ExtEquipCost

    The criteria to find will be in columns B and C. Updates will be made in columns E-G, and target.xls will be open. How would you adapt your code for this? Please help.

    Thanks in advance!

    redness
    Last edited by Redness86; 11-03-2006 at 12:03 PM.

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Redness
    Happy to have a look at this, but please post in a new question with a reference here.
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •