Macros running slow

EvansB2

Board Regular
Joined
Nov 25, 2008
Messages
245
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I'm running the code below and it is taking 2 minutes to run. The code is repeated six times in the same module to identify the different workbooks and then copy over the relevant date in the stipulated range, this one being "HouseTypeB".

I can physically see the figures being updated when running the macro each time and I would though it should be instant.

Any help would be much appreciated.

Regards
Ben

Sub HouseTypeB()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Set x = ThisWorkbook.Sheets(2)<o:p></o:p>
Set a = Workbooks("Lifecycle Model_WYPA").Sheets(3)<o:p></o:p>
For i = 19 To 74<o:p></o:p>
For J = 5 To 29<o:p></o:p>
<o:p></o:p>
x.Cells(i, J) = a.Cells(i, J)<o:p></o:p>
<o:p></o:p>
Next J<o:p></o:p>
<o:p></o:p>
Next i<o:p></o:p>
<o:p></o:p>
On Error GoTo complete<o:p></o:p>
<o:p></o:p>
complete:<o:p></o:p>
MsgBox "Lifecycle Updated", vbInformation<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
 
Change Sektor's code to:
Rich (BB code):
Sub HouseTypeB()
    
    Dim x As Worksheet, a As Worksheet
    
    Set x = ThisWorkbook.Sheets(2)
    Set a = Workbooks("Lifecycle Model_WYPA").Sheets(3)
    
    a.Range("E19:AC74").Copy 
    x.Range("E19").PasteSpecial Paste:=xlValues
    
    MsgBox "Lifecycle Updated", vbInformation

End Sub
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Only values.

Code:
Sub HouseTypeB()
    
    Dim x As Worksheet, a As Worksheet
    
    Set x = ThisWorkbook.Sheets(2)
    Set a = Workbooks("Lifecycle Model_WYPA").Sheets(3)
    
    a.Range("E19:AC74").Copy
    x.Range("E19").PasteSpecial xlPasteValues
    
    MsgBox "Lifecycle Updated", vbInformation

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top