Shakeable_Drip
Board Regular
- Joined
- May 30, 2023
- Messages
- 52
- Office Version
- 365
- Platform
- 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
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
back to true before and after the delay?
full macro below
VBA Code:
LastRow = sht2.Cells(Rows.Count, LastColumn).End(xlUp).Row + 1
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
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