Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Slow code when used as VBA code instead of macro (copying visible columns)

I have a macro that copys three columns Worksheet1 and pastes them
into Worksheet2. The code is run from a Worksheet3 using a command
button that hits a macro containing the following code:

Sheets("Worksheet1").Select
Columns("C:E").Select
Selection.Copy
Sheets("Worksheet2").Select
Cells.Select
ActiveSheet.Paste


That works fine, but I tried to move this code to the
Worksheet_Activate event for Worksheet3 with:

Application.Run ("Macro1")

With this it takes a long time to run and I often get an "Out of Stack
Space" error.

I've also tried just using:

Worksheets("Worksheet2").Columns("A:C").Value =
Worksheets("Worksheet1").Columns("C:E").Value

but, this copies all the cells...I need only the visible cells after a
filter has been applied. Any ideas? Thanks!

-Josh

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Slow code when used as VBA code instead of macro (copying visible columns)

I just realized that I also have the following code that returns the
focus back to Worksheet3 at the end of the code....if I take this out
it runs fine, but I need the focus to return to Worksheet3.

Worksheets ("Worksheet3").select

So, the original code was:
Sheets("Worksheet1").Select
Columns("C:E").Select
Selection.Copy
Sheets("Worksheet2").Select
Cells.Select
ActiveSheet.Paste
Worksheets ("Worksheet3").select

-Josh

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Slow code when used as VBA code instead of macro (copying visiblecolumns)

I'd use:

worksheets("worksheet1").range("C:e").copy _
destination:=worksheets("sheet2").range("a1")

And it kind of sounds like you have an event that's firing after each change.
Maybe something like:

application.enableevents = false
worksheets("worksheet1").range("C:e").copy _
destination:=worksheets("sheet2").range("a1")
application.enableevents = true

to stop the event from starting.

" wrote:

I have a macro that copys three columns Worksheet1 and pastes them
into Worksheet2. The code is run from a Worksheet3 using a command
button that hits a macro containing the following code:

Sheets("Worksheet1").Select
Columns("C:E").Select
Selection.Copy
Sheets("Worksheet2").Select
Cells.Select
ActiveSheet.Paste

That works fine, but I tried to move this code to the
Worksheet_Activate event for Worksheet3 with:

Application.Run ("Macro1")

With this it takes a long time to run and I often get an "Out of Stack
Space" error.

I've also tried just using:

Worksheets("Worksheet2").Columns("A:C").Value =
Worksheets("Worksheet1").Columns("C:E").Value

but, this copies all the cells...I need only the visible cells after a
filter has been applied. Any ideas? Thanks!

-Josh


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Slow code when used as VBA code instead of macro (copying visible columns)

Thanks, Dave that worked beautifully! Much appreciated.

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
Modification in the CODE to HIDE rows and columns that start with ZERO (code given) Thulasiram[_2_] Excel Programming 4 September 26th 06 04:15 AM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM
Sheet Code Module: copying code to [email protected][_2_] Excel Programming 2 December 14th 04 01:57 AM
copying text via linked cell from combo box to macro code pagelocator Excel Programming 0 November 16th 04 09:04 AM
Copying/moving code in a macro [email protected] Excel Programming 0 September 18th 03 12:12 AM


All times are GMT +1. The time now is 10:53 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"