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

I have the following macro that runsa a UDF to delete blank rows (every other
row). The formula is inserted in cell E11 and copied down for for each line
where Col B is not empty. It works just fine, however, there are only 100+
lines and it runs very slowly. Is there something Ican do to speed it up?

Sub BudgetJobNo()
'
Sheets("Budget").Select

Call RowsJoinData(2) '<where column 2 (B) is blank for every row to delete

Application.DisplayAlerts = False
Application.ScreenUpdating = False

JobNo = "=IF(ISERROR(LEFT(Budget!B11,FIND(""
"",Budget!B11)-1))=FALSE,LEFT(Budget!B11,FIND("" "",Budget!B11)-1),"" "")"
Range("E11").Value = JobNo

'And then copy them down to the last line.
Range("e11:e11").Select
Selection.Copy
CR = 11
Do While Cells(CR, 2) < ""
Range(Cells(CR, 5), Cells(CR, 5)).Select
ActiveSheet.Paste
CR = CR + 1
Loop
Application.DisplayAlerts = True
Application.ScreenUpdating = True


End Sub

--
Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Help to speed up this macro

On 9 May, 09:15, Jim G wrote:
*The formula is inserted in cell E11 and copied down for for each line
where Col B is not empty. *It works just fine, however, there are only 100+
lines and it runs very slowly. *Is there something Ican do to speed it up?


A number of things spring to mind..
Do you need the equation in the cells, or just the result?

As a first step to speeding things up, do away with all the copy/paste
stuff.

ie replace this bit ...

* * JobNo = "=IF(ISERROR(LEFT(Budget!B11,FIND(""
"",Budget!B11)-1))=FALSE,LEFT(Budget!B11,FIND("" "",Budget!B11)-1),"" "")"
* * Range("E11").Value = JobNo
* * Range("e11:e11").Select
* * Selection.Copy
* * CR = 11
* * Do While Cells(CR, 2) < ""
* * * * Range(Cells(CR, 5), Cells(CR, 5)).Select
* * * * ActiveSheet.Paste
* * * * CR = CR + 1
* * Loop


With...

JobNo = "=IF(ISERROR(LEFT(Budget!B11,FIND("""",Budget!
B11)-1))=FALSE,LEFT(Budget!B11,FIND("" "",Budget!B11)-1),"" "")"
CR = 11
Do While Cells(CR, 2) < ""
Cells(CR, 5).Value = JobNo
CR = CR + 1
Loop

Not that I have bothered to test this, so it might be wrong in detail,
though right in principle.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default Help to speed up this macro

Thanks for that,
I probably don't need the formulas, but I like to chck that users haven't
typed over a result.

I haven't tested you solution but I can see the logic.

In the meantime, I'd manged to come up with this whcih seemed to do the trick:

Sub BudgetJobNo()
'
' BudgetJobNo Macro
'
Dim myRange As String

Sheets("Budget").Select

Call RowsJoinData(2) '<where column 2 (B) is blank for every row to delete

Application.DisplayAlerts = False
Application.ScreenUpdating = False

lastrow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
myRange = "(" & "E11:E" & lastrow & ")"
JobNo = "=IF(ISERROR(LEFT(Budget!B11,FIND(""
"",Budget!B11)-1))=FALSE,LEFT(Budget!B11,FIND("" "",Budget!B11)-1),"" "")"
Range("E11").Value = JobNo

'And then copy them down to the last line.
Range(myRange).Select
Selection.FillDown
Range("E11").Select

Application.DisplayAlerts = True
Application.ScreenUpdating = True


End Sub


--
Jim


"atpgroups" wrote:

On 9 May, 09:15, Jim G wrote:
The formula is inserted in cell E11 and copied down for for each line
where Col B is not empty. It works just fine, however, there are only 100+
lines and it runs very slowly. Is there something Ican do to speed it up?


A number of things spring to mind..
Do you need the equation in the cells, or just the result?

As a first step to speeding things up, do away with all the copy/paste
stuff.

ie replace this bit ...

JobNo = "=IF(ISERROR(LEFT(Budget!B11,FIND(""
"",Budget!B11)-1))=FALSE,LEFT(Budget!B11,FIND("" "",Budget!B11)-1),"" "")"
Range("E11").Value = JobNo
Range("e11:e11").Select
Selection.Copy
CR = 11
Do While Cells(CR, 2) < ""
Range(Cells(CR, 5), Cells(CR, 5)).Select
ActiveSheet.Paste
CR = CR + 1
Loop


With...

JobNo = "=IF(ISERROR(LEFT(Budget!B11,FIND("""",Budget!
B11)-1))=FALSE,LEFT(Budget!B11,FIND("" "",Budget!B11)-1),"" "")"
CR = 11
Do While Cells(CR, 2) < ""
Cells(CR, 5).Value = JobNo
CR = CR + 1
Loop

Not that I have bothered to test this, so it might be wrong in detail,
though right in principle.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Help to speed up this macro

On 9 May, 12:14, Jim G wrote:

* * 'And then copy them down to the last line.
* * Range(myRange).Select
* * Selection.FillDown
* * Range("E11").Select


Try to avoid selecting stuff to work on it. If the user clicks a cell
or changes sheets it all goes wrong.

This will do pretty much the same thing as you have done there
regardless of which sheet is at the front, or what else is happening.

Range(myRange, Myrange.end(xlDown)).Value = JobNo
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Help to speed up this macro

try turning off calculation at the beginning and turning it back on when you're
done
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With


' your code

With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
End With

--


Gary


"Jim G" wrote in message
...
I have the following macro that runsa a UDF to delete blank rows (every other
row). The formula is inserted in cell E11 and copied down for for each line
where Col B is not empty. It works just fine, however, there are only 100+
lines and it runs very slowly. Is there something Ican do to speed it up?

Sub BudgetJobNo()
'
Sheets("Budget").Select

Call RowsJoinData(2) '<where column 2 (B) is blank for every row to delete

Application.DisplayAlerts = False
Application.ScreenUpdating = False

JobNo = "=IF(ISERROR(LEFT(Budget!B11,FIND(""
"",Budget!B11)-1))=FALSE,LEFT(Budget!B11,FIND("" "",Budget!B11)-1),"" "")"
Range("E11").Value = JobNo

'And then copy them down to the last line.
Range("e11:e11").Select
Selection.Copy
CR = 11
Do While Cells(CR, 2) < ""
Range(Cells(CR, 5), Cells(CR, 5)).Select
ActiveSheet.Paste
CR = CR + 1
Loop
Application.DisplayAlerts = True
Application.ScreenUpdating = True


End Sub

--
Jim



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
Speed Up this macro? Joe2007 Excel Programming 20 November 5th 07 07:18 PM
can anybody speed up this macro matthias Excel Programming 2 October 16th 06 04:26 PM
How to speed up this macro? Ctech Excel Programming 19 October 6th 05 04:28 PM
Speed-up a macro! maca[_3_] Excel Programming 3 July 15th 05 06:40 PM
Speed up macro rn Excel Discussion (Misc queries) 3 February 21st 05 01:25 PM


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