Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default automatically run script

Hi there,

I have the following code which I want to execute either:

- At regular time intervals (30 sec)
- When I activate the worksheet
- When smt changes in sheet 1 column A.

Thanks

Sub MirrorColumnA()
Const sourceSheetName = "Sheet1" ' change as needed
Dim sourceSheet As Worksheet
Const destinationSheetName = "Sheet2" ' change as needed
Dim destSheet As Worksheet
Dim anyRangeAddress As String
Dim sourceRange As Range
Dim destRange As Range


Set sourceSheet = Worksheets(sourceSheetName)
Set destSheet = Worksheets(destinationSheetName)
anyRangeAddress = "A1:A" & _
sourceSheet.Range("A" & Rows.Count).End(xlUp).Row
Set sourceRange = sourceSheet.Range(anyRangeAddress)
Set destRange = destSheet.Range(anyRangeAddress)
destRange.Value = sourceRange.Value
Set destRange = Nothing
Set destSheet = Nothing
Set sourceRange = Nothing
Set sourceSheet = Nothing
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default automatically run script

#1. You may want to take a look at Chip Pearson's notes on .ontime:
http://www.cpearson.com/excel/OnTime.aspx

#2 & 3. Look at a worksheet event (this code goes behind the worksheet):

Option Explicit
Private Sub Worksheet_Activate()
call MirrorColumnA
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("A:A")) Is Nothing Then
Exit Sub
End If
Call mirrorColumnA
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Chip Pearson has some instructions on events:
http://www.cpearson.com/excel/Events.aspx

David McRitchie has some notes, too:
http://www.mvps.org/dmcritchie/excel/event.htm



dangerd wrote:

Hi there,

I have the following code which I want to execute either:

- At regular time intervals (30 sec)
- When I activate the worksheet
- When smt changes in sheet 1 column A.

Thanks

Sub MirrorColumnA()
Const sourceSheetName = "Sheet1" ' change as needed
Dim sourceSheet As Worksheet
Const destinationSheetName = "Sheet2" ' change as needed
Dim destSheet As Worksheet
Dim anyRangeAddress As String
Dim sourceRange As Range
Dim destRange As Range

Set sourceSheet = Worksheets(sourceSheetName)
Set destSheet = Worksheets(destinationSheetName)
anyRangeAddress = "A1:A" & _
sourceSheet.Range("A" & Rows.Count).End(xlUp).Row
Set sourceRange = sourceSheet.Range(anyRangeAddress)
Set destRange = destSheet.Range(anyRangeAddress)
destRange.Value = sourceRange.Value
Set destRange = Nothing
Set destSheet = Nothing
Set sourceRange = Nothing
Set sourceSheet = Nothing
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default automatically run script

On Jan 25, 2:46*pm, Dave Peterson wrote:
#1. *You may want to take a look at Chip Pearson's notes on .ontime:http://www.cpearson.com/excel/OnTime.aspx

#2 & 3. *Look at a worksheet event (this code goes behind the worksheet):

Option Explicit
Private Sub Worksheet_Activate()
* *call MirrorColumnA
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
* * If Intersect(Target, Me.Range("A:A")) Is Nothing Then
* * * * Exit Sub
* * End If * *
* * Call mirrorColumnA
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:http://www.mvps.org/dmcritchie/excel/getstarted.htm

Chip Pearson has some instructions on events:http://www.cpearson.com/excel/Events.aspx

David McRitchie has some notes, too:http://www.mvps.org/dmcritchie/excel/event.htm





dangerd wrote:

Hi there,


I have the following code which I want to execute either:


- At regular time intervals (30 sec)
- When I activate the worksheet
- When smt changes in sheet 1 column A.


Thanks


Sub MirrorColumnA()
* Const sourceSheetName = "Sheet1" ' change as needed
* Dim sourceSheet As Worksheet
* Const destinationSheetName = "Sheet2" ' change as needed
* Dim destSheet As Worksheet
* Dim anyRangeAddress As String
* Dim sourceRange As Range
* Dim destRange As Range


* Set sourceSheet = Worksheets(sourceSheetName)
* Set destSheet = Worksheets(destinationSheetName)
* anyRangeAddress = "A1:A" & _
* *sourceSheet.Range("A" & Rows.Count).End(xlUp).Row
* Set sourceRange = sourceSheet.Range(anyRangeAddress)
* Set destRange = destSheet.Range(anyRangeAddress)
* destRange.Value = sourceRange.Value
* Set destRange = Nothing
* Set destSheet = Nothing
* Set sourceRange = Nothing
* Set sourceSheet = Nothing
End Sub


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Whow...Thanks!
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
help with the VB script Igneshwara reddy[_2_] Excel Worksheet Functions 4 March 6th 07 08:54 PM
VB Script Krista Excel Worksheet Functions 4 May 20th 06 03:12 PM
VB script help - please!! Anthony Excel Discussion (Misc queries) 1 July 13th 05 01:19 AM
VBA script help..Please !!!! Anthony Excel Discussion (Misc queries) 6 June 6th 05 01:40 PM
VB script help..please !! Anthony Excel Worksheet Functions 2 June 5th 05 03:26 PM


All times are GMT +1. The time now is 01:56 PM.

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

About Us

"It's about Microsoft Excel"