RandomUserCode
New Member
- Joined
- Aug 4, 2021
- Messages
- 26
- Office Version
- 365
- Platform
- Windows
- MacOS
I have a schedule in sheet1 and a schedule in sheet2. I want to "subtract" the table range in sheet2 with the table range in sheet1. Sheet2 is the "skeleton" of the schedule, and the determined values in specific cells. Sheet1 is the "skeleton table", just with cells added afterwards. So i want to reset the table in sheet1, to its "skeleton", which is seen in sheet2.
Made this code, but cant make it work:
The schedule tables looks like this:
Made this code, but cant make it work:
VBA Code:
Function RangeMinus(r1 As Range, r2 As Range) As Range
Dim rCell As Range
For Each rCell In r1
If Intersect(rCell, r2) Is Nothing Then
If RangeMinus Is Nothing Then
Set RangeMinus = rCell
Else
Set RangeMinus = Application.Union(RangeMinus, rCell)
End If
End If
Next rCell
End Function
VBA Code:
Sub test()
Dim rMinus As Range
Set rMinus = RangeMinus(Sheets(2).Range("B2:F10"), Sheets(1).Range("B2:F10"))
MsgBox rMinus.Address(0, 0)
End Sub
The schedule tables looks like this: