Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7988437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:27:09+00:00 2026-06-04T12:27:09+00:00

I have VBA code that takes my data on the master worksheet and puts

  • 0

I have VBA code that takes my data on the “master” worksheet and puts it in the other sheets in a workbook. The problem I am having is that the new data doesn’t update automatically. I would like to develop code that will automatically update my worksheets. This is the code that I have now.

Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
If Range("B" & i).Value = "AP" Then Rows(i).Copy Destination:=Sheets("AP").Range("A" & Rows.Count).End(xlUp).Offset(1)
If Range("B" & i).Value = "*AP" Then Rows(i).Copy Destination:=Sheets(" If Range("B" & i).Value = "CSW" Then Rows(i).Copy Destination:=Sheets("CSW").Range("A" & Rows.Count).End(xlUp).Offset(1)
If Range("B" & i).Value = "CO" Then Rows(i).Copy Destination:=Sheets("CO").Range("A" & Rows.Count).End(xlUp).Offset(1)
If Range("B" & i).Value = "PSR" Then Rows(i).Copy Destination:=Sheets("PSR").Range("A" & Rows.Count).End(xlUp).Offset(1)
Next i
End Sub

This puts the data in the other sheets, but when I input new data into the “master” worksheet, the data does not update in the other sheets. I’ve tried other methods to include auto filter, but they haven’t worked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:27:11+00:00Added an answer on June 4, 2026 at 12:27 pm

    Use the worksheet_change event in your “master” spreadsheet. When data is updated in the “master” sheet, it will raise the worksheet_change event and you can call your code to update the other sheets.

    You can find detailed instructions on how to use it here: http://www.ozgrid.com/VBA/run-macros-change.htm

    I set up a working example with your code. The workbook has 6 sheets (“master”, “AP”, “All AP”, “CSW”, “CO”, and “PSR”). Row 1 in each sheet is assumed to be a header row. Once you have your workbook set up with the code below, any changes you make on the “master” sheet will raise the worksheet_change event, causing all of the destination sheets in the workbook to get updated with the most current data.

    Follow these steps to get it to work:

    Add the following in the code module of the master sheet:

    _

    Option Explicit
    
        Private Sub Worksheet_Change(ByVal Target As Range)
            Call UpdateFromMaster
        End Sub
    

    Add these subs into a standard module:

    _

    Sub UpdateFromMaster()
        ' clear whatever you had previously written to the destination sheets
        Call ResetDestinationSheets
    
        ' the code you already had
        Dim LR As Long, i As Long
        LR = Range("A" & Rows.Count).End(xlUp).Row
        For i = 2 To LR
        If Range("B" & i).Value = "AP" Then Rows(i).Copy Destination:=Sheets("AP").Range("A" & Rows.Count).End(xlUp).Offset(1)
        If Range("B" & i).Value = "*AP" Then Rows(i).Copy Destination:=Sheets("All AP").Range("A" & Rows.Count).End(xlUp).Offset(1)
        If Range("B" & i).Value = "CSW" Then Rows(i).Copy Destination:=Sheets("CSW").Range("A" & Rows.Count).End(xlUp).Offset(1)
        If Range("B" & i).Value = "CO" Then Rows(i).Copy Destination:=Sheets("CO").Range("A" & Rows.Count).End(xlUp).Offset(1)
        If Range("B" & i).Value = "PSR" Then Rows(i).Copy Destination:=Sheets("PSR").Range("A" & Rows.Count).End(xlUp).Offset(1)
        Next i
    
    End Sub
    

    _

    Sub ResetDestinationSheets()
        '== not elegant, but will work in your example
    
        Call ResetThisSheet("AP")
        Call ResetThisSheet("ALL AP") ' I didn't know what you called this sheet
        Call ResetThisSheet("CSW")
        Call ResetThisSheet("CO")
        Call ResetThisSheet("PSR")
    
    End Sub
    

    _

    Sub ResetThisSheet(ByRef SheetToClear As String)
        Sheets(SheetToClear).Range("A2:B" & Rows.Count).Clear
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel workbook, which using VBA code that opens another workbook, copies
I have some VBA code that needs to talk to a running c# application.
I have a method in my VBA code that needs to be assigned to
I have a bunch of VBA code that I'd like to throw in a
Does anyone have any vb.net or vba code that will format excel values or
I am porting Excel VBA to VB.NET. I have a function that takes a
I have an Excel VBA function that takes a number of optional parameters, including
i have some vba code that i need to convert to c# Select Case
I currently have some VBA code that runs through and modifies all my calendar
I have Office 2003 VBA code that uses the technique described here to embed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.