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
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hia
Not sure you can create public variables in ThisWorkbook, so this
Code:
Public CallingSheet As Worksheet
should be moved into a standard module
 
Upvote 0
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
 
Upvote 0
Thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,568
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top