Is this macro running too fast?

Shakeable_Drip

Board Regular
Joined
May 30, 2023
Messages
50
Office Version
  1. 365
Platform
  1. Windows
I have 2 small issues with my macro in its current state, the first is when stepping thru the code, in sub Diagram 1
VBA Code:
LastRow = sht2.Cells(Rows.Count, LastColumn).End(xlUp).Row + 1
throws a generic error, however when the macro is run there are no issues so... shrug?
the 2nd comes in when I was cleaning it up removing all the .selection deals. I did a test run and it appears that some of my conditional formatting is activated with the statement false.
Also an index and match that I use for a picture that changes depending on material type is not updating properly.
I think I should insert some kind of delay that fully processes the worksheet before its copied to the next worksheet: what kind of delay should I use and do i need to set
VBA Code:
Application.ScreenUpdating = False 'turn screenupdating off
Application.EnableEvents = False 'turn events off
back to true before and after the delay?
full macro below
VBA Code:
Sub ReportGenerator()
' second attempt
' if "z" = 1 then
' call report 1
' else:
' call report 1 and call report cycle
Application.ScreenUpdating = False 'turn screenupdating off
Application.EnableEvents = False 'turn events off
If Range("G1").Value = 1 Then
Call Report1
    Else:
    Call Report1
    For x = 1 To Range("G1") - 1
    Call ReportCycle
    Next x
End If
Application.ScreenUpdating = True 'turn screenupdating ON
Application.EnableEvents = True 'turn events ON
End Sub
Sub Report1()
' make first report and
' If "y" = 1 then
' call diagram 1
' else:
' call Diagram 1 and  call Diagram cycle
Dim sht1 As Worksheet
Dim sht2 As Worksheet

Set sht1 = Sheets("HELPER")
Set sht2 = Sheets("REPORTS")

sht1.Range("E3").Value = 1
'Application.CutCopyMode = False
sht1.Range("U3:AN49").Copy
ActiveSheet.Paste Destination:=sht2.Range("A3") 'required syntax to paste pictures and formats. below pastes values.
sht2.Range("A3").pastespecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
If Range("G3").Value = 1 Then
Call Diagram1
    Else:
    Call Diagram1
    For x = 1 To Range("G3") - 1
    Call Diagram1
    Next x
End If
End Sub
Sub Report2()
' Basically same as report one, but paste destination is dynamic, not absolute (xltoleft)
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim LastColumn As Long
Dim LastRow As Long

Set sht1 = Sheets("HELPER")
Set sht2 = Sheets("REPORTS")
LastColumn = sht2.Cells(3, Columns.Count).End(xlToLeft).Column + 4

Range("E3").Value = 1
Range("U3:AN49").Copy
ActiveSheet.Paste Destination:=sht2.Cells(3, LastColumn)
sht2.Cells(3, LastColumn).pastespecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
If Range("G3").Value = 1 Then
Call Diagram1
    Else:
    Call Diagram1
    For x = 1 To Range("G3") - 1
    Call Diagram1
    Next x
End If
End Sub
Sub ReportCycle()
' increase "A" by 1
' call report 2
Range("H2") = Range("H2") + 1
'this advances to the next and makes a report
Call Report2
End Sub
Sub Diagram1()
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim LastRow4Copy As Long
Dim LastColumn As Long
Dim LastRow As Long

Set sht1 = Sheets("HELPER")
Set sht2 = Sheets("REPORTS")
LastRow4Copy = sht1.Cells(Rows.Count, 21).End(xlUp).Row
LastColumn = sht2.Cells(3, Columns.Count).End(xlToLeft).Column - 16
LastRow = sht2.Cells(Rows.Count, LastColumn).End(xlUp).Row + 1

sht1.Range("U50", sht1.Range("AN" & LastRow4Copy)).Copy
ActiveSheet.Paste Destination:=sht2.Cells(LastRow, LastColumn)
sht2.Cells(LastRow, LastColumn).pastespecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
Range("E3") = Range("E3") + 1
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Only a guess, but your code is full of unqualified references which may be messing things up when you try to single step. Recommend that you review your code and fully qualify all range, row, and column references.

1687717949949.png
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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