PDA

View Full Version : Excel refresh page



nicolaforni
11-12-2009, 06:10 AM
Hi,

If I save macro to refresh sheet2 starting from sheet1 this works fine.

Sheets("Sheet2").Select
Range("C4").Select
Application.Run "BLPLinkReset"
ActiveCell.FormulaR1C1 = "2"
Range("C5").Select
End Sub
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.

Private Sub CommandButton1_Click()
Sheets("Sheet2").Select
Range("C4").Select
Application.Run "BLPLinkReset"
ActiveCell.FormulaR1C1 = "2"
Range("C5").Select
End Sub
Why is it that the same code does not work using the command button?

:dunno

Thanks!
Nick

mdmackillop
11-12-2009, 06:13 AM
Try this, putting MyMacro in a Standard module.


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

nicolaforni
11-12-2009, 08:26 AM
Thanks,

mdmackillop
11-12-2009, 08:52 AM
Basically, code in a Sheet module doesn't like working with another sheet.