VBA - Populate cells on other sheets

wthbloop

New Member
Joined
Oct 1, 2014
Messages
10
I'm writing a workbook that will pull external data into it via CSV. It will then populate cells in the workbook.

However, it has to be Sales Person proof. So, when a sales person modifies a cell, it needs to populate the similar cells on other sheets. I have a sheet named Input (Sheet3), which holds all of these values. This took me to using VBA to handle the cell (re)population. So when a sales person edits something like 'Customer Name' on one sheet, every 'Customer Name' on other sheets will be changed.

Here's what I've got. The problem I'm having is that when I change G8 in Sheet14, I get an error that states "Object Required". Debugging takes me to Line12 on Sheet3; hovering over the code, reveals "CallingSheet = Empty". Am I referencing something wrong? Comparing objects incorrectly? Is there an easier way to do all this and still be 'idiot proof'?

ThisWorkbook
Code:
Public CallingSheet As Worksheet

Module1
Code:
Public Type SheetCellRef
    RefSheet As Worksheet
    RefCell As Range
End Type


Sheet14
Code:
Private Sub Worksheet_Change(ByVal Target As Range)    
    Set CallingSheet = Sheet14
    
    Sheet3.Range("B84") = Range("G8")
    
End Sub

Sheet3
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Select Case Target.Address
        Case "$B$84"
            Dim AffectedSheets(1 To 2) As Module1.SheetCellRef
            Set AffectedSheets(1).RefSheet = Sheet14
            Set AffectedSheets(1).RefCell = Range("G8")
            Set AffectedSheets(2).RefSheet = Sheet15
            Set AffectedSheets(2).RefCell = Range("A7")
            
            For i = 1 To 2
                If Not AffectedSheets(i).RefSheet Is CallingSheet Then 'Line12
                    AffectedSheets(i).RefSheet.Range(AffectedSheets(i).RefCell) = Range("B84")
                End If
            Next i
            
        Case Else
            MsgBox "Nope" 'If nothing matches
    End Select


End Sub
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
Hia
Not sure you can create public variables in ThisWorkbook, so this
Code:
Public CallingSheet As Worksheet
should be moved into a standard module
 

wthbloop

New Member
Joined
Oct 1, 2014
Messages
10
Hia
Not sure you can create public variables in ThisWorkbook, so this
Code:
Public CallingSheet As Worksheet
should be moved into a standard module
You're right, and I also set it to global.

That, and some tweaks to Sheet3 fixed it.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)        Select Case Target.Address
        Case "$B$84"
            Dim AffectedSheets(1 To 2) As Module1.SheetCellRef
            'Define all the sheets/cells that are affected by this change
            Set AffectedSheets(1).RefSheet = Sheet14
            Set AffectedSheets(1).RefCell = Sheet14.Range("G8")
            Set AffectedSheets(2).RefSheet = Sheet15
            Set AffectedSheets(2).RefCell = Sheet15.Range("A7")
            
            For i = LBound(AffectedSheets, 1) To UBound(AffectedSheets, 1)
                If Not AffectedSheets(i).RefSheet Is CallingSheet Then
                    AffectedSheets(i).RefCell = Range("B84")
                End If
            Next i
            
        Case Else
            MsgBox "Nope"
    End Select


End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
Thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,109,434
Messages
5,528,742
Members
409,832
Latest member
Misspears10

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top