Consolidation of x2 Marcos

Bradzo

New Member
Joined
Nov 15, 2017
Messages
11
Hi everyone,

Seeking assistance in combining two sub routines that were previously separate and running them together, I have tried many variations, and this is the best I can come up with.
It is slow and cumbersome and if anyone could take a look and speed it up and make more reliable, I would really appreciate the assistance.
Thanks Brad

Sub Update()
Dim wks As Worksheet
Dim ws As Worksheet
Dim rng As Range

Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("Master").Delete
On Error GoTo 0
Application.DisplayAlerts = True

Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "Master"
Sheets("ADC").Select

For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "master" Then
For Each c In ws.Range("u3:u" & Cells(Rows.Count, "u").End(xlUp).Row)
If c.Value = "" Then c.Value = c.Offset(, -3).Value
Next
End If
Next

For Each wks In ThisWorkbook.Worksheets
If Not wks.Name = "master" Then
wks.Range("s3:u" & wks.Cells(Rows.Count, "u").End(xlUp).Row).Copy _
Destination:=Worksheets("Master").Cells(Rows.Count, "A").End(xlUp).Offset(1)
End If
Next


Sheets("info").Select
Range("u" & Rows.Count).End(xlUp).Offset(1, 0).Value = Format(Now, "dd/mm/yyyy HH:mm:ss")

Application.ScreenUpdating = True


End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I've noticed that there are two On Error statements. One of them has no Go To line.
VBA Code:
Sub Update()
Dim wks As Worksheet
Dim ws As Worksheet
Dim rng As Range

Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next                               'Here's the first one.
ActiveWorkbook.Worksheets("Master").Delete
On Error GoTo 0                                         'Here's the second one with no 0: reference.
Application.DisplayAlerts = True

Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "Master"
Sheets("ADC").Select

For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "master" Then
For Each c In ws.Range("u3:u" & Cells(Rows.Count, "u").End(xlUp).Row)
If c.Value = "" Then c.Value = c.Offset(, -3).Value
Next
End If
Next

For Each wks In ThisWorkbook.Worksheets
If Not wks.Name = "master" Then
wks.Range("s3:u" & wks.Cells(Rows.Count, "u").End(xlUp).Row).Copy _
Destination:=Worksheets("Master").Cells(Rows.Count, "A").End(xlUp).Offset(1)
End If
Next


Sheets("info").Select
Range("u" & Rows.Count).End(xlUp).Offset(1, 0).Value = Format(Now, "dd/mm/yyyy HH:mm:ss")

Application.ScreenUpdating = True


End Sub
 
Upvote 0
Solution
Hi Skyybot,

Thanks for the feedback and taking the time to look over.

Greatly appreciated, Brad
 
Upvote 0
You have two loops the walk through the Worksheets in your Workbook. Excluding the "master" worksheet you are:
1) (1st loop) -setting the value of a cell (looks like Col R -- Col U offset -3), and
2) (2nd loop) - copying the last row in each sheet and writing to the "Master" sheet

It appears that you could eliminate one of the loops (probably the second one) and write to the "Master" sheet as part of the first loop. I think this would help to speed up the execution time.

How many sheets are you stepping through? You could pre-calculate the end row of each sheet as a separate loop and store them in an array, then use these array values within your loop. ...
Just a thought.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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