-
Solved: Excel refresh page
Hi,
If I save macro to refresh sheet2 starting from sheet1 this works fine.
[vba]Sheets("Sheet2").Select
Range("C4").Select
Application.Run "BLPLinkReset"
ActiveCell.FormulaR1C1 = "2"
Range("C5").Select
End Sub[/vba]
If I add a command button and use it to run same code this does not work.
I get error message:
Run-time error '1004' Select method of Range class failed.
[vba]Private Sub CommandButton1_Click()
Sheets("Sheet2").Select
Range("C4").Select
Application.Run "BLPLinkReset"
ActiveCell.FormulaR1C1 = "2"
Range("C5").Select
End Sub[/vba]
Why is it that the same code does not work using the command button?
Thanks!
Nick
Last edited by Aussiebear; 11-14-2009 at 03:16 PM.
Reason: Added VBA tags to code
-
Try this, putting MyMacro in a Standard module.
[VBA]
Private Sub CommandButton1_Click()
call MyMacro
End Sub
Sub MyMacro()
Sheets("Sheet2").Select
Range("C4").Select
Application.Run "BLPLinkReset"
ActiveCell.FormulaR1C1 = "2"
Range("C5").Select
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
-
Basically, code in a Sheet module doesn't like working with another sheet.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules