Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Could this code be faster?

Hi There.. I was hoping some clever being could help me out...
I am quite new to VBA and the code below works (shocked and stunned)
its just that it takes a long time to run as the workbook is quite
large..
is there any way to make it quicker?
I know I could stop it updating in the statusbar but its nice to know
where the process is upto....thanks in advance...

ste

Public Sub controldata()

Dim b1 As Variant
Dim b2 As Variant
Dim b3 As Variant
Dim b4 As Variant
Dim b5 As Variant
Dim xlrow As Long

Application.StatusBar = False

Application.ScreenUpdating = False

For sheetnumber = 1 To 56

SheetName = "S" & Format(sheetnumber, "##0")
Sheets(SheetName).Select

ActiveSheet.Cells(3, 36).Select

xlrow = 3

Do While Not (ActiveSheet.Cells(xlrow, 1).Value = "")

b1 = ActiveSheet.Cells(xlrow, 3).Value
b2 = ActiveSheet.Cells(xlrow, 4).Value
b3 = ActiveSheet.Cells(xlrow, 5).Value
b4 = ActiveSheet.Cells(xlrow, 6).Value
b5 = ActiveSheet.Cells(xlrow, 7).Value

ActiveCell = b1 & ("&") & b2
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b1 & ("&") & b3
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b1 & ("&") & b4
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b1 & ("&") & b5
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b2 & ("&") & b3
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b2 & ("&") & b4
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b2 & ("&") & b5
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b3 & ("&") & b4
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b3 & ("&") & b5
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b4 & ("&") & b5
ActiveCell = ActiveCell.Offset(1, -9).Select

'ActiveCell = ActiveCell.Offset(1, -23).Select

xlrow = xlrow + 1

Application.StatusBar = "System Status: " & Format(xlrow /
ActiveSheet.Cells(1, 2).Value, "00%") & SheetName & " of Data is
completed ..."

Loop

ActiveCell.Value = ""

Application.StatusBar = False

Next

Application.ScreenUpdating = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Could this code be faster?

Hi Ste

Definitely. Two things:

1 Don't select cells. Change

ActiveCell.Offset(0, 1).Select
ActiveCell = b4 & ("&") & b5

to

ActiveCell.Offset(0, 1).Value = b4 & ("&") & b5

or even better

Cells(xlrow, columnnumber).Value = b4 & ("&") & b5

2) When you enter into cells, Excel recalculates. How long time that takes
depends on how many formulas you have. Put
Application.Calculation = xlCalculationManual
in the beginning (up with screenupdating), and
Application.Calculation = xlCalculationAutomatic
at the end.

Yes, keep the statusbar. It seems longer if absolutely nothing is seen, even
when it's actually faster. Anything 2 seconds should show progress or
"working" indication.

--
HTH. Best wishes Harald
Excel MVP
Followup to newsgroup only please

"ste mac" skrev i melding
om...
Hi There.. I was hoping some clever being could help me out...
I am quite new to VBA and the code below works (shocked and stunned)
its just that it takes a long time to run as the workbook is quite
large..
is there any way to make it quicker?
I know I could stop it updating in the statusbar but its nice to know
where the process is upto....thanks in advance...

ste

Public Sub controldata()

Dim b1 As Variant
Dim b2 As Variant
Dim b3 As Variant
Dim b4 As Variant
Dim b5 As Variant
Dim xlrow As Long

Application.StatusBar = False

Application.ScreenUpdating = False

For sheetnumber = 1 To 56

SheetName = "S" & Format(sheetnumber, "##0")
Sheets(SheetName).Select

ActiveSheet.Cells(3, 36).Select

xlrow = 3

Do While Not (ActiveSheet.Cells(xlrow, 1).Value = "")

b1 = ActiveSheet.Cells(xlrow, 3).Value
b2 = ActiveSheet.Cells(xlrow, 4).Value
b3 = ActiveSheet.Cells(xlrow, 5).Value
b4 = ActiveSheet.Cells(xlrow, 6).Value
b5 = ActiveSheet.Cells(xlrow, 7).Value

ActiveCell = b1 & ("&") & b2
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b1 & ("&") & b3
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b1 & ("&") & b4
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b1 & ("&") & b5
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b2 & ("&") & b3
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b2 & ("&") & b4
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b2 & ("&") & b5
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b3 & ("&") & b4
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b3 & ("&") & b5
ActiveCell = ActiveCell.Offset(0, 1).Select
ActiveCell = b4 & ("&") & b5
ActiveCell = ActiveCell.Offset(1, -9).Select

'ActiveCell = ActiveCell.Offset(1, -23).Select

xlrow = xlrow + 1

Application.StatusBar = "System Status: " & Format(xlrow /
ActiveSheet.Cells(1, 2).Value, "00%") & SheetName & " of Data is
completed ..."

Loop

ActiveCell.Value = ""

Application.StatusBar = False

Next

Application.ScreenUpdating = True

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Could this code be faster?

Thanks Harald...that was a great help...now it goes like a rocket..
cheers....
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 can my macro run faster ? Roger[_2_] New Users to Excel 12 October 26th 09 12:57 PM
Can be here some changes for a faster speed ? ytayta555 Excel Worksheet Functions 3 July 30th 08 06:42 PM
can this be done faster? Frank Excel Discussion (Misc queries) 7 August 9th 07 10:02 PM
Can faster CPU+larger/faster RAM significantly speed up recalulati jmk_li Excel Discussion (Misc queries) 2 September 28th 05 10:24 AM
faster macro _______Tim_______ Excel Programming 6 August 28th 03 03:01 PM


All times are GMT +1. The time now is 01:30 AM.

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"