Harmandeep
New Member
- Joined
- Dec 19, 2022
- Messages
- 19
- Office Version
- 365
- Platform
- Windows
Hello Everyone,
I am looking for a quick response form VBA experts. I am new to VBA coding and i have written a VBA code in a worksheet name(Data) and the same is running perfectly on the Data worksheet. I am trying to set a button on another work sheet named(Summary). When i am assign the same Macro Code written in Data worksheet to Summary worksheet with button. The same is running on Summary worksheet only. How can i assign the worksheet name in Code so that it can run from any worksheet in the same file. I am sharing my code below.
Thanks in advance.
''''Sub Report()
lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
Range("u1").FormulaR1C1 = "Check1"
Range("U1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("u2").Formula = "=IFERROR(VLOOKUP(P2,'BillDesk_Setllement Report'!C:P,14,0),"""")"
Range("u2").AutoFill Range("u2:u" & lr)
Sheets("Data").Select
Range("v1").FormulaR1C1 = "Diff1"
Range("V1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("v2").Formula = "=IFERROR(Q2-U2,"""")"
Range("v2").AutoFill Range("v2:v" & lr)
Sheets("Data").Select
Range("w1").FormulaR1C1 = "Duplicate Flag"
Range("w1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("w2").Formula = "=IF(COUNTIF($P$2:$P$300000,$P2)>1,""Duplicate"",""Not Duplicate"")"
Range("w2").AutoFill Range("w2:w" & lr)
Sheets("Data").Select
Range("x1").FormulaR1C1 = "Remarks1"
Range("x1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("x2").Formula = "=IFERROR(IF(AND(Q2=U2),""Matched"",IF(AND(Q2>U2),""Discount"",IF(Q2<>U2,""Not Bill Desk""))),""Not Bill Desk"")"
Range("x2").AutoFill Range("x2:x" & lr)
End Sub
I am looking for a quick response form VBA experts. I am new to VBA coding and i have written a VBA code in a worksheet name(Data) and the same is running perfectly on the Data worksheet. I am trying to set a button on another work sheet named(Summary). When i am assign the same Macro Code written in Data worksheet to Summary worksheet with button. The same is running on Summary worksheet only. How can i assign the worksheet name in Code so that it can run from any worksheet in the same file. I am sharing my code below.
Thanks in advance.
''''Sub Report()
lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
Range("u1").FormulaR1C1 = "Check1"
Range("U1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("u2").Formula = "=IFERROR(VLOOKUP(P2,'BillDesk_Setllement Report'!C:P,14,0),"""")"
Range("u2").AutoFill Range("u2:u" & lr)
Sheets("Data").Select
Range("v1").FormulaR1C1 = "Diff1"
Range("V1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("v2").Formula = "=IFERROR(Q2-U2,"""")"
Range("v2").AutoFill Range("v2:v" & lr)
Sheets("Data").Select
Range("w1").FormulaR1C1 = "Duplicate Flag"
Range("w1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("w2").Formula = "=IF(COUNTIF($P$2:$P$300000,$P2)>1,""Duplicate"",""Not Duplicate"")"
Range("w2").AutoFill Range("w2:w" & lr)
Sheets("Data").Select
Range("x1").FormulaR1C1 = "Remarks1"
Range("x1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("x2").Formula = "=IFERROR(IF(AND(Q2=U2),""Matched"",IF(AND(Q2>U2),""Discount"",IF(Q2<>U2,""Not Bill Desk""))),""Not Bill Desk"")"
Range("x2").AutoFill Range("x2:x" & lr)
End Sub