CincyExcel1
New Member
- Joined
- Aug 7, 2022
- Messages
- 4
- Office Version
- 2016
- Platform
- Windows
I started using VBA in excel
I have a spreadsheet named "MasterReport"
1. this macro will create a new spreadsheet and name it with the value in MasterReport's cell "B2" (OldDatax)
2. the existing data will be copied and transferred to the "oldDatax" sheet everytime I run the macro
3. Fresh data will be pasted in the "MasterReport" and
4. I want to create a conditional formatting to highlight the changes (difference between the 2 spread sheets ("MasterReport" and Newly created spreadsheet.
Because I want to maintain the Old records, my idea was to simply update the name of MasterReport's cell "B2" every time I want to "archive the existing values in MasterReport, then the name of the new spreadsheet will be changing, that is why I want name the new sheet from MasterReport's cell "B2
it seems to be working until I tried to implement the formula for the conditional formatting Formula1:="=A5<> msOld !A5" but it is not working.
Any suggestions on how to fix this?
Here is the code:
Sub Macro1()
'
' Macro1 Macro
'
Dim MySheet As String, wsOld As Worksheet
Sheets("MasterReport").Select
Sheets.Add(After:=Sheets("MasterReport")).Name = Range("B2")
'Sheets.Add(After:=Sheets("MasterReport")).Name = "SheetName"
MySheet = Sheets("MasterReport").Range("B2").Value
Set wsOld = Sheets(MySheet)
Worksheets("MasterReport").Activate
Range("MasterTable[#All]").Copy
wsOld.Range("A4").PasteSpecial Paste:=xlPasteValues 'This line NEEDS to be in a "solo" line separate from the above or VBA "gets confused"
wsOld.Activate
Range("A:A,H:H,J:J,K:K,O:O,Q:Q").Select
Selection.NumberFormat = "m/d/yyyy"
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
Sheets("MasterReport").Activate
Range("MasterTable").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=A5<> ' wsOld' !A5"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.399945066682943
End With
Selection.FormatConditions(1).StopIfTrue = False
I have a spreadsheet named "MasterReport"
1. this macro will create a new spreadsheet and name it with the value in MasterReport's cell "B2" (OldDatax)
2. the existing data will be copied and transferred to the "oldDatax" sheet everytime I run the macro
3. Fresh data will be pasted in the "MasterReport" and
4. I want to create a conditional formatting to highlight the changes (difference between the 2 spread sheets ("MasterReport" and Newly created spreadsheet.
Because I want to maintain the Old records, my idea was to simply update the name of MasterReport's cell "B2" every time I want to "archive the existing values in MasterReport, then the name of the new spreadsheet will be changing, that is why I want name the new sheet from MasterReport's cell "B2
it seems to be working until I tried to implement the formula for the conditional formatting Formula1:="=A5<> msOld !A5" but it is not working.
Any suggestions on how to fix this?
Here is the code:
Sub Macro1()
'
' Macro1 Macro
'
Dim MySheet As String, wsOld As Worksheet
Sheets("MasterReport").Select
Sheets.Add(After:=Sheets("MasterReport")).Name = Range("B2")
'Sheets.Add(After:=Sheets("MasterReport")).Name = "SheetName"
MySheet = Sheets("MasterReport").Range("B2").Value
Set wsOld = Sheets(MySheet)
Worksheets("MasterReport").Activate
Range("MasterTable[#All]").Copy
wsOld.Range("A4").PasteSpecial Paste:=xlPasteValues 'This line NEEDS to be in a "solo" line separate from the above or VBA "gets confused"
wsOld.Activate
Range("A:A,H:H,J:J,K:K,O:O,Q:Q").Select
Selection.NumberFormat = "m/d/yyyy"
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
Sheets("MasterReport").Activate
Range("MasterTable").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=A5<> ' wsOld' !A5"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.399945066682943
End With
Selection.FormatConditions(1).StopIfTrue = False