Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default automatic macro

How do I make it so my code runs everytime I click on a certain worksheet.

This is my code so far.

Sub TripsCopy()
Dim Trips As Integer
Dim tr As Integer

Active.Sheet (Expense)
Trips = InputBox("Enter Number of Trips Taken")
If Trips 1 Then
'Sheets("Individual Trip").Select
For tr = 1 To Trips
Sheets("Individual Trip").Copy After:=Sheets(Sheets.Count)
Next
End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default automatic macro

In the worksheet code area include this event macro:

Private Sub Worksheet_Activate()
Call TripsCopy
End Sub



Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200781


"Ewing25" wrote:

How do I make it so my code runs everytime I click on a certain worksheet.

This is my code so far.

Sub TripsCopy()
Dim Trips As Integer
Dim tr As Integer

Active.Sheet (Expense)
Trips = InputBox("Enter Number of Trips Taken")
If Trips 1 Then
'Sheets("Individual Trip").Select
For tr = 1 To Trips
Sheets("Individual Trip").Copy After:=Sheets(Sheets.Count)
Next
End If
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default automatic macro

awesome thank you!

"Ewing25" wrote:

How do I make it so my code runs everytime I click on a certain worksheet.

This is my code so far.

Sub TripsCopy()
Dim Trips As Integer
Dim tr As Integer

Active.Sheet (Expense)
Trips = InputBox("Enter Number of Trips Taken")
If Trips 1 Then
'Sheets("Individual Trip").Select
For tr = 1 To Trips
Sheets("Individual Trip").Copy After:=Sheets(Sheets.Count)
Next
End If
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic run of Macro Frank Excel Discussion (Misc queries) 1 February 21st 07 03:10 PM
Automatic run of Macro Tom Ogilvy Excel Discussion (Misc queries) 0 February 21st 07 02:33 PM
Automatic Macro Momo Excel Programming 1 October 21st 04 12:01 PM
Automatic Macro in Excel MMM[_2_] Excel Programming 1 February 3rd 04 03:53 PM
Automatic Macro ianripping[_3_] Excel Programming 3 January 15th 04 05:22 PM


All times are GMT +1. The time now is 06:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"