gallopingant
New Member
- Joined
- Aug 19, 2020
- Messages
- 9
- Office Version
- 365
- Platform
- MacOS
I created a custom user form using regular cells as inputs with a reset and submit button. The reset button works fine and erases the form. Here is the flow I want to achieve:
User inputs data into form and clicks submit. Based on the name of the country they select, it gets copied and pasted into that worksheet. The form is cleared so another entry can be made.
The submit button is where I'm having some trouble. I've attempted two ways of accomplishing this:
- Simple copying and pasting of the information
- Trying to do a With loop and count the rows
I tried to follow this tutorial but didn't have much luck:
Here is the relevant code from that video:
I don't think I fully understand some of this code, specifically how he is copying and pasting it into the correct sheet. I also don't understand what is happening with setting variables as worksheets. I think if someone could explain that part, it would help me understand better.
Any help is appreciated.
User inputs data into form and clicks submit. Based on the name of the country they select, it gets copied and pasted into that worksheet. The form is cleared so another entry can be made.
The submit button is where I'm having some trouble. I've attempted two ways of accomplishing this:
- Simple copying and pasting of the information
- Trying to do a With loop and count the rows
I tried to follow this tutorial but didn't have much luck:
Here is the relevant code from that video:
VBA Code:
Sub Submit_Details()
Dim shCountry As Worksheet
Dim shForm As Worksheet
Dim iCurrentRow As Integer
Dim sCountryName As String
Set shForm = ThisWorkbook.Sheets("Form")
sCountryName = shForm.Range("H11").Value
Set shCountry = ThisWorkbook.Sheets(sCountryName)
iCurrentRow = shCountry.Range("A" & Application.Rows.Count).End(xlUp).Row + 1
With shCountry
.Cells(iCurrentRow, 1) = iCurrentRow - 1
.Cells(iCurrentRow, 2) = shForm.Range("H7")
.Cells(iCurrentRow, 3) = shForm.Range("H9")
.Cells(iCurrentRow, 4) = shForm.Range("H11")
.Cells(iCurrentRow, 5) = shForm.Range("H13")
.Cells(iCurrentRow, 6) = shForm.Range("H15")
.Cells(iCurrentRow, 7) = Application.UserName
.Cells(iCurrentRow, 8) = Format([Now()], "DD-MMM-YYYY HH:MM:SS")
End With
shForm.Range("H7, H9, H11, H13, H15").Value = ""
MsgBox "Data submitted successfully!"
End Sub
Any help is appreciated.