Faster Macro

heffo500

New Member
Joined
Sep 28, 2016
Messages
44
Hi

Could this macro be more efficient?

Thanks

VBA Code:
Sub daily()
'Added by LH 24.10.18
Dim lr As Long, lr2 As Long, wb As Workbook, stock As Worksheet, wk As Workbook, TAconcat As String, lastrow As Long
'''''set objects''''''
    Set wk = ThisWorkbook
Set Capstock = wk.Sheets("Capstock Report")
        Application.DisplayAlerts = False
'''''''Clear contents from REC'''''''''
Sheets("stock Report").Select
lr = Range("D" & Rows.Count).End(xlUp).Row
Range("A2:T" & lr).Select
                Selection.ClearContents
'''''error proof'''''''
On Error GoTo errhandler:
Workbooks.Open "G:\Report.xls"
Set wb = ActiveWorkbook
wb.Sheets(2).Select
lr2 = Range("C" & Rows.Count).End(xlUp).Row
Range("A1:N" & lr2).Copy
stock.Range("A2:N" & lr2).PasteSpecial
wb.Close
Set wb = Nothing
'remove marching ants

Application.CutCopyMode = False

''''''Input formulas to check for breaks'''''''
 Range("O1:T1 ").Copy
Range("O3:T" & lr2).PasteSpecial

' add headings
Range("O2") = "CCY"
Range("P2") = "Number"
Range("Q2") = "SC"
Range("R2") = "F"
Range("S2") = "AMOUNT"
Range("T2") = "Match?"

'''''error handler''''''
errhandler:
Debug.Print Err.Number, Err.Description
Application.DisplayAlerts = True
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Your code seems a little confused. You declare stock but then use Capstock when assigning the worksheet, so you should end up with a runtime error later on. Also, are the "Capstock report" and "stock report" sheets different?
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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