Macro OverDrive "XXXXX to 5 cells together"

4 Barrel Harold

New Member
Joined
Jun 15, 2018
Messages
21
Mission Impossible,
For me that is LOL, Hey MrExcel Guys and Gals, this is what I'm trying to do and I'm not sure what it called or what I need to do to accomplish this task. On my worksheet I have 5 cells (A1, C105, G55, R21, & Z21) and what I would like to happen is if I enter data in any random cell R21 of the 5 cells listed above the data update the other 4 cells, and vise versa if choose any of the other 4 Cells and enter new data. Any Help Greatly Appreciated Thanks
 
Gallen, Thanks Hey I'm only needing to repeat this code in my workbook 3 times but will be using it in others, so what is this error handing code that you have mentioned??? Sounds like this error handling code is an important best practice to know about. Thanks
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
As you are disabling events (application wide) they will remain disabled if your code should error out while disabled. Hence the 'good practice' comment

This is the full code with error handling.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim sAddress As String 'address of range of cells
        Dim bAddress As String 'address of range of cells


    'if an error occurs handle it
    On Error GoTo errHandle
    
    sAddress = "A1,C15,G5,R2,Z14"   'Cells used as examples.
    bAddress = "A4,C19,G9,R6,Z18"   'Cells used as examples.
    
    Application.EnableEvents = False
    
    'check if the cell that has changed is one of our cells in 'sAddress'
    If Not Intersect(Range(sAddress), Target) Is Nothing Then Range(sAddress) = Target
    
    'check if the cell that has changed is one of our cells in 'bAddress'
    If Not Intersect(Range(bAddress), Target) Is Nothing Then Range(bAddress) = Target
    
    Application.EnableEvents = True


Exit Sub
'this section will only execute if an error occurs.
errHandle:
    'ensure events are enabled
    Application.EnableEvents = True
    'Display information on the error
    MsgBox Err.Description, vbCritical, "Error number: " & Err.Number
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,576
Members
449,173
Latest member
Kon123

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