I am creating a vba UserForm that after completion of the form, a string variable with the form details will paste into another sheet in the workbook.
I want to paste the value dStr into a new sheet after the use clicks on the addBtn. Would appreciate any help on this. I've read elsewhere that you can set the variable public, but not exactly sure how to do that either.
Sub UserForm_Initialize()
Dim valueUSD, name, ric, pStr, sitchStr As String
Dim i, lRow As Long
i = 2
ric = Worksheets("Tester").Range("H" & i)
name = Worksheets("Tester").Range("B" & i)
valueUSD = Worksheets("Tester").Range("C" & i)
sitchStr = ""
dStr = ""
pStr = ric & " " & name & " " & valueUSD & " "
Label1.Caption = pStr
TextBox2.Value = ""
If activeCheck.Value = True Then
sitchStr = sitchStr + activeCheck.Caption
ElseIf itwCheck.Value = True Then
sitchStr = sitchStr + itwCheck.Caption
Else
sitchStr = ""
End If
dStr = pStr & vbNewLine & sitchStr & ", " & TextBox2.Value
End Sub
Sub addBtn_Click()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Dim myData As DataObject
Dim lastRow As Long
End Sub
dstr? Also, the lineDim valueUSD, name, ric, pStr, sitchStr As Stringdoes only declaresitchStras a string. All other variables will be of type variant, have a look here.Publicinstead ofDim. You can do this outside of the sub it runs in.Public var As String.