I have a macro that I am trying to create and the first portion works perfectly but there are times where the user will need to make manual adjustments before the final step of the macro is completed. I tried adding a Modeless userform to accomplish this but now it starts at the userform and doesn't execute the first portion of the macro first. The userform macro is listed below where I need it to be (I highlighted in red).
I am not the best at writing macros so I am sure this code isn't the cleanest...gotta start somewhere.
Thanks!
Sub DocID()
'
' DocID Macro
'
'
Sheets("MailMerge_Device").Select
Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Doc_ID").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("MailMerge_Device").Select
Range("H2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Doc_ID").Select
Range("F2").Select
ActiveSheet.Paste
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("A2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
Range("G2:G" & Cells(Rows.Count, "F").End(xlUp).Row).Formula = "=LEFT(A2,1)"
Range("H2:H" & Cells(Rows.Count, "F").End(xlUp).Row).Formula = "=LEFT(B2,1)"
Range("I2:I" & Cells(Rows.Count, "F").End(xlUp).Row).Formula = "=RIGHT(F2,4)"
Range("J2:J" & Cells(Rows.Count, "F").End(xlUp).Row).Formula = "=CONCATENATE(G2,H2,I2)"
Call MacroPause
Worksheets("Doc_ID").Range("J2:J" & Cells(Rows.Count, "F").End(xlUp).Row).Copy
Worksheets("MailMerge_Device").Range("O2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Sub MacroPause()
Load UserForm1
UserForm1.Label1 = "Make some changes, close me if finished"
MsgBox "Start of the macro"
On Error GoTo Continue
UserForm1.Show vbModeless
Do While Not UserForm1.Visible
DoEvents
Loop
Do While UserForm1.Visible
DoEvents
Loop
Continue:
MsgBox "Rest of the macro"
End Sub
I am not the best at writing macros so I am sure this code isn't the cleanest...gotta start somewhere.
Thanks!
Sub DocID()
'
' DocID Macro
'
'
Sheets("MailMerge_Device").Select
Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Doc_ID").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("MailMerge_Device").Select
Range("H2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Doc_ID").Select
Range("F2").Select
ActiveSheet.Paste
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("A2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
Range("G2:G" & Cells(Rows.Count, "F").End(xlUp).Row).Formula = "=LEFT(A2,1)"
Range("H2:H" & Cells(Rows.Count, "F").End(xlUp).Row).Formula = "=LEFT(B2,1)"
Range("I2:I" & Cells(Rows.Count, "F").End(xlUp).Row).Formula = "=RIGHT(F2,4)"
Range("J2:J" & Cells(Rows.Count, "F").End(xlUp).Row).Formula = "=CONCATENATE(G2,H2,I2)"
Call MacroPause
Worksheets("Doc_ID").Range("J2:J" & Cells(Rows.Count, "F").End(xlUp).Row).Copy
Worksheets("MailMerge_Device").Range("O2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Sub MacroPause()
Load UserForm1
UserForm1.Label1 = "Make some changes, close me if finished"
MsgBox "Start of the macro"
On Error GoTo Continue
UserForm1.Show vbModeless
Do While Not UserForm1.Visible
DoEvents
Loop
Do While UserForm1.Visible
DoEvents
Loop
Continue:
MsgBox "Rest of the macro"
End Sub