I'm writing an excel sheet with a macro userform to replace a paper system we have in my work place. Its a simple form with two frames; one containing 3 option buttons and another containing a textbox and then 3 more options. The code I wrote looks like this..
Dim Option1A As String
If Frame1.OptionButton1Low Then
Option1A = "Low"
ElseIf Frame1.OptionButton1Mid Then
Option1A = "Medium"
ElseIf Frame1.OptionButton1High Then
Option1A = "High"
End If
Dim Risk1 As String
Risk1 = TextBox1.Value
If Option1A = "Medium" And Risk1 = "" Then
MsgBox ("Please enter a description of your risk mitigation")
ElseIf Option1A = "High" And Risk1 = "" Then
MsgBox ("Please enter a description of your risk mitigation")
End If
Dim Option1B As String
If FrameF1.OptionButton1FLow Then
Option1B = "Low"
ElseIf FrameF1.OptionButton1FMid Then
Option1B = "Medium"
ElseIf FrameF1.OptionButton1FHigh Then
Option1B = "High"
End If
ActiveCell.Offset(g, 15).Value = Option1A
ActiveCell.Offset(g, 16).Value = Risk1
ActiveCell.Offset(g, 17).Value = Option1B
Simple right? This does exactly what I want it to, the thing is I have 1 pair of frames in this piece of code, there are 17 more pairs on the userform. All the text boxes, frames, option buttons and Strings are named sequentially. So right now I could just copy and paste it 17 more times and get the result I want.
I'm wondering if there's a way to write a Do While loop that changes the numbers, so Option1A becomes Option2A, Option3A and OptionButton1FLow becomes OptionButton2FLow etc. Basically change all the number 1's in the code to x value.
I haven't found any suggestions in my research and am starting to think this isn't possible,
Any insight is greatly appreciated,
Cheers in advance,
Sean