Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default Why does this code take so long to execute.

' Delete all lines
Dim lin As Line
For Each lin In ActiveSheet.Lines
If lin.Name Like "Line*" Then
lin.Delete
End If
Next

The longer I have worked on the project with this code, the more sluggish
this seemed to be. Each time I run the macro with this code It will create
300-500 line segments. This delete code is the 1st thing that is done to
clear out all lines from the previous execution and then re-draw the lines
based on current data. The code that draws the lines has much more meat to
its code, (lots of loops and conversions) but it runs very fast (a matter of
seconds). As I step through the code (single step), the cursor seems to hang
on the lin.Delete for about 1-3 seconds, Of course watching the execution
i'm sure takes significantly longer, but I have seen this macro take about
3-5 minutes to complete it's deleting of all the lines.

As the lines are being created I question the autonumber that is generated,
Line15023 for example, I am wondering if that might be causing some overhead.


Is there a more efficient way to delete all lines?
I have also added code to turn off "calculation" before the deletes and
turning recalc back on afterwards, but that didnt seem to help.



--
Regards,
John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why does this code take so long to execute.

Activesheet.Lines.Delete

--
Regards,
Tom Ogilvy

"John Keith" wrote in message
...
' Delete all lines
Dim lin As Line
For Each lin In ActiveSheet.Lines
If lin.Name Like "Line*" Then
lin.Delete
End If
Next

The longer I have worked on the project with this code, the more sluggish
this seemed to be. Each time I run the macro with this code It will

create
300-500 line segments. This delete code is the 1st thing that is done to
clear out all lines from the previous execution and then re-draw the lines
based on current data. The code that draws the lines has much more meat

to
its code, (lots of loops and conversions) but it runs very fast (a matter

of
seconds). As I step through the code (single step), the cursor seems to

hang
on the lin.Delete for about 1-3 seconds, Of course watching the execution
i'm sure takes significantly longer, but I have seen this macro take about
3-5 minutes to complete it's deleting of all the lines.

As the lines are being created I question the autonumber that is

generated,
Line15023 for example, I am wondering if that might be causing some

overhead.


Is there a more efficient way to delete all lines?
I have also added code to turn off "calculation" before the deletes and
turning recalc back on afterwards, but that didnt seem to help.



--
Regards,
John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default Why does this code take so long to execute.

Excelent! that worked in the blink of an eye,
Thanks Tom!

"Tom Ogilvy" wrote:

Activesheet.Lines.Delete

--
Regards,
Tom Ogilvy

"John Keith" wrote in message
...
' Delete all lines
Dim lin As Line
For Each lin In ActiveSheet.Lines
If lin.Name Like "Line*" Then
lin.Delete
End If
Next

The longer I have worked on the project with this code, the more sluggish
this seemed to be. Each time I run the macro with this code It will

create
300-500 line segments. This delete code is the 1st thing that is done to
clear out all lines from the previous execution and then re-draw the lines
based on current data. The code that draws the lines has much more meat

to
its code, (lots of loops and conversions) but it runs very fast (a matter

of
seconds). As I step through the code (single step), the cursor seems to

hang
on the lin.Delete for about 1-3 seconds, Of course watching the execution
i'm sure takes significantly longer, but I have seen this macro take about
3-5 minutes to complete it's deleting of all the lines.

As the lines are being created I question the autonumber that is

generated,
Line15023 for example, I am wondering if that might be causing some

overhead.


Is there a more efficient way to delete all lines?
I have also added code to turn off "calculation" before the deletes and
turning recalc back on afterwards, but that didnt seem to help.



--
Regards,
John




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Making sheets visible & hidden

Hey there,

I'm a HUGE novice with excel programming, through self-teaching I've covered
quite a few simple commands but still there are loads to learn - yay.

Anyhoo, I want to be able to control what sheets some of my staff @ work
have access to.
I can easily make the tabs hidden, but unfortunately most of my staff aren't
that simple!

What I have so far is a simple userform system which checks payroll numbers
and passwords - and their access privilege...
What I want to be able to do is say... give level 1 users access to a single
"staff" sheet...
Give level 2 users access to "staff" and "holiday" sheets...
give level 3 users access to "staff", "holiday" and "reports" sheets...

I am aware of the Visible, Hidden and VeryHidden variables for sheets - how
to use them is the issue...

I keep coming up with ideas like...

If user_payroll.Value = Reference("PAYROLL1") Then
password_form.Show
Else
MsgBox("Payroll not recognised."), , "Oops!"
----------------------------------------------------------------------------------------------
If user_pass.Value = Reference("PASSWORD1") Then
Make Sheets("staff").Visible
Else
MsgBox("Password not recognised."), , "Oops!"


Then on logging out/closing the spreadsheet, the sheet(s) would become
VeryHidden again...

Any ideas how I can make this work - like I said I'm self taught and I can't
find any good learning resources for this - the books I have on excel VBA
don't mention anything like this.

All input _WILL_ be greatly appreciated!

Also - any ideas on how I could instead create a similar system by using an
excel spreadsheet as a database then taking all the login details from there
would be excellent.

thanks,

Kai


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Making sheets visible & hidden

Not sure why you are posting this in this thread, but see a possible
approach in response to your first posting.

--
Regards,
Tom Ogivy

"Xlyr" wrote in message
. uk...
Hey there,

I'm a HUGE novice with excel programming, through self-teaching I've

covered
quite a few simple commands but still there are loads to learn - yay.

Anyhoo, I want to be able to control what sheets some of my staff @ work
have access to.
I can easily make the tabs hidden, but unfortunately most of my staff

aren't
that simple!

What I have so far is a simple userform system which checks payroll

numbers
and passwords - and their access privilege...
What I want to be able to do is say... give level 1 users access to a

single
"staff" sheet...
Give level 2 users access to "staff" and "holiday" sheets...
give level 3 users access to "staff", "holiday" and "reports" sheets...

I am aware of the Visible, Hidden and VeryHidden variables for sheets -

how
to use them is the issue...

I keep coming up with ideas like...

If user_payroll.Value = Reference("PAYROLL1") Then
password_form.Show
Else
MsgBox("Payroll not recognised."), , "Oops!"
--------------------------------------------------------------------------

--------------------
If user_pass.Value = Reference("PASSWORD1") Then
Make Sheets("staff").Visible
Else
MsgBox("Password not recognised."), , "Oops!"


Then on logging out/closing the spreadsheet, the sheet(s) would become
VeryHidden again...

Any ideas how I can make this work - like I said I'm self taught and I

can't
find any good learning resources for this - the books I have on excel VBA
don't mention anything like this.

All input _WILL_ be greatly appreciated!

Also - any ideas on how I could instead create a similar system by using

an
excel spreadsheet as a database then taking all the login details from

there
would be excellent.

thanks,

Kai




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
how to execute the fill function down a long column Harvey Excel Discussion (Misc queries) 5 September 4th 09 08:30 PM
Execute vba code on cell exit Bill (Unique as my name) Excel Discussion (Misc queries) 2 May 24th 07 03:48 PM
my excel formulas are too long to execute find and replace jmh33 Excel Worksheet Functions 1 February 22nd 06 05:35 PM
When does Code Execute on a List Box? John Baker Excel Programming 0 January 11th 05 08:24 PM
execute code for all 12 months Herb Buist Excel Programming 0 July 19th 03 03:43 PM


All times are GMT +1. The time now is 07:22 AM.

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"