Hi guys i am trying to call a macro which i have recorded in a spreadsheet, dont know what is happening to it but it seems to be giving me an error. I am using a simple comand buttone to call 2 macros, one of them is working perfectly but the other one is giving me an error. below is the code:
Private Sub CommandButton1_Click()
RngSelect.Show 'this is a userform which opens on this command button
Call period 'this is the macro which is not working
Call Search 'this macro is working fine
End Sub
On clicking this button vba gives me a compile error, saying 'Expected variable or procedure,not module'.
However if i omit this one and just have the second macro it works fine.
I have tried moving this to other places in the worksheet to trigger it but everywhere it is giving me an error. Thus im guessing it might be an error with the macro itself which is as below:
Sub period()
'
' period macro
'
Application.EnableEvents = False
With Sheets("Sheet1")
.Range("C63").Select
Selection.copy
Range("C64").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'
With Sheets("Pivot for Map")
.PivotTables("PivotTable1").PivotFields("YrPrComp").CurrentPage = _
Sheets("Sheet1").Range("E64").Value
With Sheets("Sheet1")
Range("C66:C193").copy
Range("E66").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With
End With
Sheets("Pivot for Map").PivotTables("PivotTable1").PivotFields("YrPrComp").CurrentPage = _
Sheets("Sheet1").Range("C64").Value
Sheets("Sheet1").Select
End With
Application.EnableEvents = True
End Sub
Could you guys have a look at this and let me know what is going wrong here, i was working on this a couple of hours ago and both the macros were working fine, no problems at all, dont know why its doing this now.
Regards,
Abz
Bookmarks