fahadalambd
New Member
- Joined
- Sep 16, 2022
- Messages
- 31
- Office Version
- 2016
- Platform
- Windows
Hi everyone, I am new in VBA Macro Scripting.
I am trying to sync data between two sheets ("Sheet1" and "Sheet2") in the same excel file.
I found the solution from this website (How to synchronize data between two sheets or ranges in Excel - VBA and VB.Net Tutorials, Education and Programming Services). and this is the code -
Problem is that I can't call this procedure in a Module. Please some one help to solve this problem. Here is the screen-shot -
I am trying to sync data between two sheets ("Sheet1" and "Sheet2") in the same excel file.
I found the solution from this website (How to synchronize data between two sheets or ranges in Excel - VBA and VB.Net Tutorials, Education and Programming Services). and this is the code -
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sourceSheet As Worksheet, targetSheet As Worksheet
Dim syncRange As String
Dim isInRange
'Set the source and target sheets here
Set sourceSheet = Sheet1
Set targetSheet = sheet2
'This will be the column that needs to be synced
syncRange = "A1:C8"
'Check if the modified cell lies within the range to be synced
Set isInRange = Application.Intersect(Target, Range(syncRange))
If isInRange Is Nothing Then
'Do nothing if the cell falls outside the range
Else
'Else sync the cell contents
targetSheet.Range(Target.Address) = sourceSheet.Range(Target.Address)
End If
End Sub
Problem is that I can't call this procedure in a Module. Please some one help to solve this problem. Here is the screen-shot -