Userform to pause Macro then resume when form is closed

lwebbie

New Member
Joined
Feb 28, 2017
Messages
24
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
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I would recommend either an inputBox, or encasing the entire thing in a UserForm. I'm not sure the rest of your code and, in the future, use code tags to post code.

Code:
 
Upvote 0
I don't think an inputbox will work because some of the data needs to be fixed but it will vary what cells of data. The entire code is posted above not sure what a code tag is.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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