thewrestler723
New Member
- Joined
- Jul 15, 2022
- Messages
- 1
- Office Version
- 2016
- Platform
- Windows
Hi all,
I'm trying to create a data entry form for a colleague, and don't understand why this is happening: I have fields for first name, last name, and two different date fields (WL date and active LA date). I am looking to have the entered data entered into a sheet with other data that's already sorted alphabetically by last name. My code is properly finding the correct spot for the new data based on alphabetic order, and inserts a new row and the first and last names fine. But it simply doesn't do anything when the lines to write the dates into cells is run. I ran the code in "Step-Into" mode and the lines that are supposed to write the dates to the sheet run without error, but nothing happens when they run. Any suggestions? I am quite new to VBA.
Also, I'm wondering if there's some way to write formulas into cells using VBA? I tried to do so by writing a string of the formula into a cell but it's also not doing anything when it runs (Please forgive me if me using ActiveCell to reference a cell and create a formula is a dumb way to do it, lol).
Note: I've tried to label all my text boxes intuitively, their name reflects the value they hold.
I'm trying to create a data entry form for a colleague, and don't understand why this is happening: I have fields for first name, last name, and two different date fields (WL date and active LA date). I am looking to have the entered data entered into a sheet with other data that's already sorted alphabetically by last name. My code is properly finding the correct spot for the new data based on alphabetic order, and inserts a new row and the first and last names fine. But it simply doesn't do anything when the lines to write the dates into cells is run. I ran the code in "Step-Into" mode and the lines that are supposed to write the dates to the sheet run without error, but nothing happens when they run. Any suggestions? I am quite new to VBA.
Also, I'm wondering if there's some way to write formulas into cells using VBA? I tried to do so by writing a string of the formula into a cell but it's also not doing anything when it runs (Please forgive me if me using ActiveCell to reference a cell and create a formula is a dumb way to do it, lol).
Note: I've tried to label all my text boxes intuitively, their name reflects the value they hold.
VBA Code:
Private Sub SubmitButton_Click()
'Prepare sorting process by activating top of column
Range("D7").Activate
'Store entered last name in str1 variable
Dim str1 As String
str1 = LastNameTextBox
'Loop thru all values alphabetically lower than the entered string to find correct spot in column
While str1 > ActiveCell.Value
ActiveCell.Offset(1, 0).Activate
Wend
'Insert row and write data to sheet
ActiveCell.EntireRow.Insert
ActiveCell.Value = str1
ActiveCell.Offset(0, -1).Value = FirstNameTextBox.Value
'Everything above works fine, everything below runs without error but simply does nothing, the cells I reference are just blank after running
ActiveCell.Offset(0, 1).Value = WLDateTextBox.Value
ActiveCell.Offset(0, 3).Value = ActiveLATextBox.Value
ActiveCell.Offset(0, 4).Value = "=" & ActiveCell.Offset(0, 3) & "-" & ActiveCell.Offset(0, 1)
Unload Me
End Sub