I've got a user form I want to use to determine how to run a macro:
It has two radio buttons, Template 1 and Template 2, a combo box with two options, Public and Private, another set of radio buttons, Tier 1 and Tier 2, which only get activated if Private is selected and a checkbox at the end, Wipe Conditional Formatting.
If, for example, Template 1 is selected, I need to import two worksheets from a source file, but if Template 2 selected, I just need only one. The code for Template 1 looks currently as shown below:
I want to have something like
But further down the code, it should trigger another difference in code. This is for Template 1:
And this is for Template 2:
So I would like to use the VARIABLE from the user form to merge it in one piece of code.
Same for the variable from the combobox and other user form controls.
I hope if I can figure out how to do the first two pieces of the code I can dean with the rest myself. Currently, my modest knowledge of VBA is clearly not enough to deal with the first hurdle.
VBA Code:
Private Sub UserForm_Initialize()
'Reset the form
radiotempl1.Value = False
radiotempl2.Value = False
datatype.Clear
With datatype
.AddItem "Public"
.AddItem "Private"
End With
radiotier1.Value = False
radiotier2.Value = False
radiotier1.Enabled = False
radiotier2.Enabled = False
wipe_format.Value = True
End Sub
It has two radio buttons, Template 1 and Template 2, a combo box with two options, Public and Private, another set of radio buttons, Tier 1 and Tier 2, which only get activated if Private is selected and a checkbox at the end, Wipe Conditional Formatting.
If, for example, Template 1 is selected, I need to import two worksheets from a source file, but if Template 2 selected, I just need only one. The code for Template 1 looks currently as shown below:
VBA Code:
Set activeWB = Application.ActiveWorkbook
FileOpenDial = Application.GetOpenFilename(FileFilter:="Excel Files (*.XML), *.XML", Title:="Select File To Be Opened")
If FileOpenDial = False Then Exit Sub
Set wb = Workbooks.Open(FileOpenDial)
Sheets(Array("Accounts", "Types")).Select
Sheets(Array("Accounts", "Types")).Copy Before:=activeWB.Sheets(1)
wb.Close savechanges:=False 'or True
I want to have something like
Sheets(Array(VARIABLE)).Select
, where VARIABLE means "Accounts", "Types"
if Template 1 is selected and "Accounts"
in case of Template 2.But further down the code, it should trigger another difference in code. This is for Template 1:
VBA Code:
'FillRight Formulas
Set cfyearsno = ThisWorkbook.Sheets("FS").Range("C1:XFD1")
numrowscf = Application.WorksheetFunction.CountA(cfyearsno)
With ThisWorkbook.Sheets("CF")
Set startcell = .Range("F1")
If numrowscf = 3 Then
Set endcell = Range("F" & Rows.Count).End(xlUp).Offset(, 1)
Set finstart = .Range(startcell.Address & ":" & endcell.Address)
finstart.FillRight
ElseIf numrowscf > 3 Then
Set endcell = Range("F" & Rows.Count).End(xlUp).Offset(, 2)
Set finstart = .Range(startcell.Address & ":" & endcell.Address)
finstart.FillRight
Else
End If
End With
And this is for Template 2:
VBA Code:
Set cfyearsno = ThisWorkbook.Sheets("FS").Range("F1:J1")
numrowscf = Application.WorksheetFunction.CountA(cfyearsno)
With ThisWorkbook.Sheets("CF")
Set startcell = .Range("G1")
If numrowscf = 3 Then
Set endcell = Range("G150").Offset(, 1)
Set finstart = .Range(startcell.Address & ":" & endcell.Address)
finstart.FillRight
ElseIf numrowscf > 3 Then
Set endcell = Range("G150").Offset(, 2)
Set finstart = .Range(startcell.Address & ":" & endcell.Address)
finstart.FillRight
Else
End If
End With
Same for the variable from the combobox and other user form controls.
I hope if I can figure out how to do the first two pieces of the code I can dean with the rest myself. Currently, my modest knowledge of VBA is clearly not enough to deal with the first hurdle.