I need to create a Error Code String where certain error characters occupy certain positions in a string.
Say you have Code F and it must be in position 2.
Output: _F
Now if we have Code G which is in position 5.
Output: ____G
Now what if in an instance I have TWO errors? How can I output this string:
_F__G
User Error Prompt:

My Code:
ErrorCode = Space(CodeNumber.Value) + CodeCharacter.Value
Is there an easy way to do this? I understand I can do this for the first code adn then for the second take the earlier number (2) and subtract it from (5) and take 1 away and then space and add character. But that seems messy and difficult when we have multiple codes and spaces.
What happens when I add two strings in VBA? Say "___A" + "_B" I assume its "___A_B".
Is there anyway to get "_B_A?"
Thanks!
------------------------After trying ideas from both answers--------------------
I get this which ONLY returns ONE Error Code:
Private Sub ExportError_Click()
Dim myErr As String
myErr = ""
Dim myFile As String
myFile = "C:\Reformatted.txt"
Open myFile For Output As #1
If F_2 = True Then
AddCode "F", 2, myErr
ElseIf G_3 = True Then
AddCode "G", 3, myErr
ElseIf H_4 = True Then
AddCode "H", 4, myErr
End If
Print #1, myErr
Close #1
Shell "C:\Windows\Notepad.exe C:\Reformatted.txt", 1
End Sub
Function AddCode(Lett As String, Pos As Long, ByRef ErrString As String)
If Pos > Len(ErrString) Then
ErrString = ErrString & Space(Pos - Len(ErrString))
End If
Mid(ErrString, Pos, 1) = Lett
End Function
Private Sub UserForm_Click()
End Sub