I have a multipage user form and I can't get the data that gets updated in the form to update in excel. The code I have only updates Row 2 no matter which row I edit in the form. Here is the code I am using.
Dim currentrow As Long
Private Sub btnClose_Click()
Unload Me
End Sub
Private Sub frmDrgReg_Initialize()
Dim ws As Worksheet
Set ws = Worksheets(1)
Call resetForm
currentrow = 2
Me.txtRev = Cells(currentrow, 10)
Me.txtScale = Cells(currentrow, 11)
Me.txtProjDesc = Cells(currentrow, 12)
Me.txtFacDesc = Cells(currentrow, 13)
Me.txtItemDesc = Cells(currentrow, 14)
Me.txtType = Cells(currentrow, 15)
End Sub
Private Sub btnApply_Click()
answer = MsgBox("you are about to apply the changes", vbYesNo + vbQuestion, "Apply Changes")
If answer = vbYes Then
currentrow = 2
Cells(currentrow, 10) = Me.txtRev.Text
Cells(currentrow, 11) = Me.txtScale.Text
Cells(currentrow, 12) = txtProjDesc.Text
Cells(currentrow, 13) = txtFacDesc.Text
Cells(currentrow, 14) = txtItemDesc.Text
Cells(currentrow, 15) = txtType.Text
End If
End Sub
Private Sub ComboBox1_DropButtonClick()
Dim i As Long, LastRow As Long
LastRow = Sheets(1).Range("H" & Rows.Count).End(xlUp).Row
If Me.ComboBox1.ListCount = 0 Then
For i = 2 To LastRow
Me.ComboBox1.AddItem Sheets(1).Cells(i, "H").Value
Next i
End If
End Sub
In the Sub btnApply_Click()
how can I use a For Each loop similar to the one I have used in my resetForm sub
Public Sub resetForm()
Dim ctl As Control
For Each ctl In frmDrgReg.Controls
If TypeName(ctl) = "TextBox" Then
ctl Value = ""
End If
Next ctl
frmDrgReg.ComboBox1.SetFocus
End Sub