VBA Not Running

dawnmichelle

New Member
Joined
Nov 21, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I am using the below to consolidate several worksheets into a summary sheet within the same workbook. It was running fine until I saved and reopened the workbook and I have no clue why...... I did save it as a macro-enabled workbook and my security settings are correct. I have "debugged" and it runs through each line without generating an error. When I run the macro, it appears to be running through it but it is not actually doing anything (pulling data into the summary sheet). All thoughts are appreciated.

VBA Code:
Public Sub combine()
Dim ws  As Worksheet, _
    LR1 As Long, _
    LR2 As Long
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Summary" And ws.Name <> "MasterJE" And ws.Name <> "JE-B728" And ws.Name <> "JE-B545" And ws.Name <> "JE-B542" And ws.Name <> "JE-B541" And ws.Name <> "JE-B363" And ws.Name <> "JE-B225" And ws.Name <> "MasterIC" And ws.Name <> "JE Pivot" Then
        LR1 = Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Row + 1
        LR2 = ws.Range("A" & Rows.Count).End(xlUp).Row
        ws.Range("A7:L" & LR2).Copy Destination:=Sheets("Summary").Range("A" & LR1)
    End If
Next ws
Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:
Hi
untested but see if this update to your code resolves your issue

VBA Code:
Option Explicit
Public Sub combine()
    Dim ws           As Worksheet, wsSummary As Worksheet
    Dim LR(1 To 2)   As Long
    Dim IgnoreSheets As Variant
   
    Set wsSummary = ThisWorkbook.Worksheets("Summary")
   
    IgnoreSheets = Array("Summary", "MasterJE", "JE-B728", "JE-B545", "JE-B542", _
                   "JE-B541", "JE-B363", "JE-B225", "MasterIC", "JE Pivot")
   
    Application.ScreenUpdating = False
    For Each ws In ThisWorkbook.Worksheets
        If IsError(Application.Match(ws.Name, IgnoreSheets, 0)) Then
            LR(1) = wsSummary.Range("A" & wsSummary.Rows.Count).End(xlUp).Row + 1
            LR(2) = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
            ws.Range("A7:L" & LR(2)).Copy Destination:=wsSummary.Range("A" & LR(1))
        End If
        Erase LR
    Next ws
    Application.ScreenUpdating = True
End Sub

Dave
it is doing the same thing.............it looks like the macro is running but nothing pulls into the summary tab; here's a screenshot of my tabs just in case i have done something stupid. I am so incredibly frustrated

1700664870065.png
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Should work - Is your summary sheet completely clear i.e. have you any data further down the sheet?
Try scrolling down & see if the data is being posted much lower down.

Dave
 
Upvote 0
Should work - Is your summary sheet completely clear i.e. have you any data further down the sheet?
Try scrolling down & see if the data is being posted much lower down.

Dave
O M G - it is starting it on line 777,217..............WHY? and what on earth made you think of that?
 
Upvote 0
What happens when you change
VBA Code:
LR1 = Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Row + 1
to
VBA Code:
LR1 = Sheets("Summary").Rows(Sheets("Summary").Rows.Count).End(xlUp).Row + 1
 
Upvote 0
O M G - it is starting it on line 777,217..............WHY? and what on earth made you think of that?

because it is a problem often overlooked when people create a summary sheet - not fully clearing the data to the bottom of the used range before posting new data.

Suggest consider adding new line of code to fully clear the sheet before refreshing with new data

Something like this may work for your requirement

Rich (BB code):
Set wsSummary = ThisWorkbook.Worksheets("Summary")
   
wsSummary.UsedRange.Clear

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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