I realized I should have put Userform Combobox into the thread title. Sorry!
I'm new to VBA but not new to coding or to excel. I have used multiple google searches and youtube videos (You're welcome Alphabet) to build vba code that will copy a template worksheet, name the worksheet using an input box, and populate one cell in the new worksheet also using the inputbox method. I was also able to create a Userform containing a cascading combobox that works great...that is until I try to add the Userform data to cells in the newly created (copied from template) worksheet. I have searched high and low and I cannot, for the life of me, figure out why it is not working. I feel confident it is my green VBA skills that is making this difficult for me to troubleshoot.
Could someone help me tackle this primary challenge? Again for clarity, I simply need to get my Userform (combobox & textbox) data from the Userfrom into various cells in the newly created worksheet, hopefully using the variable containing the new worksheet name. I have much work to do beyond that, but I'm trying to just eat this bite of the elephant.
Here is my Userform code:
Private Sub cmbLandUse_Cat_Change()
Me.cmbLandUse_Type = ""
Select Case Me.cmbLandUse_Cat
Case "Agricultural"
Me.cmbLandUse_Type.RowSource = "Agricultural"
Case "Business"
Me.cmbLandUse_Type.RowSource = "Business"
Case "Industrial"
Me.cmbLandUse_Type.RowSource = "Industrial"
Case "Lawn"
Me.cmbLandUse_Type.RowSource = "Lawn"
Case "Pasture"
Me.cmbLandUse_Type.RowSource = "Pasture"
Case "Residential"
Me.cmbLandUse_Type.RowSource = "Residential"
Case "Streets"
Me.cmbLandUse_Type.RowSource = "Streets"
Case "Woodland"
Me.cmbLandUse_Type.RowSource = "Woodland"
Case Else
'do nothing
End Select
End Sub
Private Sub cbAdd_Category_Click()
Dim ssheet As Worksheet
Set ssheet = ActiveSheet.Name
'place selection into cell
ssheet.Cells(1, 4).Value = Me.cmbLandUse_Cat
ssheet.Cells(2, 4).Value = Me.cmbLandUse_Type
ssheet.Cells(3, 4).Value = CInt(Me.txbxLand_Use_Area)
End Sub
Private Sub cbCancel_Click()
Unload Me
End Sub
I suspect the issue may be in where/how I am calling the userform and that someone helping to solve this would also need my primary module code so here is that as well:
Sub Create_New_Drng_Tab()
Application.ScreenUpdating = False
Dim newName As String
newName = Application.InputBox("Name of Drainage Area", "Drainage Area Name", Type:=2)
Dim OK_zone As Integer
' Drainage Area Name Input Dialog Box, if name repeated, exits sub. If cancel, exit sub
For rep = 1 To (Worksheets.Count)
If LCase(Sheets(rep).Name) = LCase(newName) Then
MsgBox "This drainage area name already exists."
Exit Sub
End If
If newName = "False" Then Exit Sub: Rem cancel pressed
Next
' Zone Input Dialog Box, if escape exit sub
OK_zone = Application.InputBox(vbNewLine & "Geographical Zone Number 1-5" _
& vbNewLine & vbNewLine & _
"See Figure 1-13, ODOT DDM Page 1-29", "Oklahoma Zone Identification", Type:=1)
Sheets("Template").Visible = True
Sheets("Template").Copy Before:=Sheets("Template")
ActiveSheet.Name = newName
'Sheets("Template").Visible = xlVeryHidden
' Insert Zone into OK Geographical Zone Cell
Range("M12").Value = OK_zone
usfrmLand_Use_Category.Show
Application.ScreenUpdating = True
End Sub
Thanks in advance!!
JD
I'm new to VBA but not new to coding or to excel. I have used multiple google searches and youtube videos (You're welcome Alphabet) to build vba code that will copy a template worksheet, name the worksheet using an input box, and populate one cell in the new worksheet also using the inputbox method. I was also able to create a Userform containing a cascading combobox that works great...that is until I try to add the Userform data to cells in the newly created (copied from template) worksheet. I have searched high and low and I cannot, for the life of me, figure out why it is not working. I feel confident it is my green VBA skills that is making this difficult for me to troubleshoot.
Could someone help me tackle this primary challenge? Again for clarity, I simply need to get my Userform (combobox & textbox) data from the Userfrom into various cells in the newly created worksheet, hopefully using the variable containing the new worksheet name. I have much work to do beyond that, but I'm trying to just eat this bite of the elephant.
Here is my Userform code:
Private Sub cmbLandUse_Cat_Change()
Me.cmbLandUse_Type = ""
Select Case Me.cmbLandUse_Cat
Case "Agricultural"
Me.cmbLandUse_Type.RowSource = "Agricultural"
Case "Business"
Me.cmbLandUse_Type.RowSource = "Business"
Case "Industrial"
Me.cmbLandUse_Type.RowSource = "Industrial"
Case "Lawn"
Me.cmbLandUse_Type.RowSource = "Lawn"
Case "Pasture"
Me.cmbLandUse_Type.RowSource = "Pasture"
Case "Residential"
Me.cmbLandUse_Type.RowSource = "Residential"
Case "Streets"
Me.cmbLandUse_Type.RowSource = "Streets"
Case "Woodland"
Me.cmbLandUse_Type.RowSource = "Woodland"
Case Else
'do nothing
End Select
End Sub
Private Sub cbAdd_Category_Click()
Dim ssheet As Worksheet
Set ssheet = ActiveSheet.Name
'place selection into cell
ssheet.Cells(1, 4).Value = Me.cmbLandUse_Cat
ssheet.Cells(2, 4).Value = Me.cmbLandUse_Type
ssheet.Cells(3, 4).Value = CInt(Me.txbxLand_Use_Area)
End Sub
Private Sub cbCancel_Click()
Unload Me
End Sub
I suspect the issue may be in where/how I am calling the userform and that someone helping to solve this would also need my primary module code so here is that as well:
Sub Create_New_Drng_Tab()
Application.ScreenUpdating = False
Dim newName As String
newName = Application.InputBox("Name of Drainage Area", "Drainage Area Name", Type:=2)
Dim OK_zone As Integer
' Drainage Area Name Input Dialog Box, if name repeated, exits sub. If cancel, exit sub
For rep = 1 To (Worksheets.Count)
If LCase(Sheets(rep).Name) = LCase(newName) Then
MsgBox "This drainage area name already exists."
Exit Sub
End If
If newName = "False" Then Exit Sub: Rem cancel pressed
Next
' Zone Input Dialog Box, if escape exit sub
OK_zone = Application.InputBox(vbNewLine & "Geographical Zone Number 1-5" _
& vbNewLine & vbNewLine & _
"See Figure 1-13, ODOT DDM Page 1-29", "Oklahoma Zone Identification", Type:=1)
Sheets("Template").Visible = True
Sheets("Template").Copy Before:=Sheets("Template")
ActiveSheet.Name = newName
'Sheets("Template").Visible = xlVeryHidden
' Insert Zone into OK Geographical Zone Cell
Range("M12").Value = OK_zone
usfrmLand_Use_Category.Show
Application.ScreenUpdating = True
End Sub
Thanks in advance!!
JD
Last edited: