Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically Run an Excel Macro on opening 1

Status
Not open for further replies.

likelylad

IS-IT--Management
Jul 4, 2002
388
GB
How do I run the following when the excel spreadsheet opens

Sub Workbook_Open()

Range("A1").Select
Selection.Copy
Range("A4").Select
ActiveSheet.Paste

End Sub

Thanking you in advance

[Pipe]
 
If the Workbook_Open sub is in the Workbook module, it'll automatically run on opening. May I suggest a tweak to your code tho:

Private Sub Workbook_Open
Sheets("Sheetname").select
With activesheet
.range("A1").copy destination:=Activesheet.range("A4")
end with
end sub

I would say that in 99% of cases, this method of copy and pasting saves time over selecting the cell, copying to clipboard, selecting the paste cell then pasting

If your sub isn't running on open, I think you probably have the code in the wrong place:
1: Go to VB Editor
2: Double CLick on "This Workbook" in the VBA Project window
3: Select Workbook from the 1st dropdown
4: Select Open from the 2nd dropdown
5: The structure (Start sub / end sub) will automatically be put in place for you. Now all you need do is write the code ;-)
HTH
~Geoff~
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top