Forum Discussion
DonnyBahama
Aug 10, 2023Copper Contributor
Get data from input form, send it to a worksheet and row based on form values
I have a workbook with a data input form (for entering the sales numbers for today) which has a cell with =TEXT(TODAY(),"mmm") to display the (short/3-character) current month and a simila...
- Aug 10, 2023
Let's say that the cell with the month formula is A2 and the cell with the day formula is A3
And let's say that the month sheets have a header row, so day 1 is in row 2 etc.
Dim w As Worksheet Dim r As Long Set w = Worksheets(Range("A2").Value) r = Range("A3").Value + 1 ' Populate a cell in column D of the r-th row of worksheet w w.Range("D" & r).Value = ...
Does that help you on your way?
HansVogelaar
Aug 10, 2023MVP
Let's say that the cell with the month formula is A2 and the cell with the day formula is A3
And let's say that the month sheets have a header row, so day 1 is in row 2 etc.
Dim w As Worksheet
Dim r As Long
Set w = Worksheets(Range("A2").Value)
r = Range("A3").Value + 1
' Populate a cell in column D of the r-th row of worksheet w
w.Range("D" & r).Value = ...
Does that help you on your way?
- DonnyBahamaAug 10, 2023Copper Contributor
HansVogelaarThank you so much! That was very helpful! That code wrote the specified cell value to row 10, column D of the AUG sheet. (Today being the 10th of August.) You were right - the AUG sheet does have a header row. It took some trial and error (I'm very much a VBA novice) to figure out how to increment today's day number but I figured it out. This code worked perfectly:
Dim ws As Worksheet Dim rn As Byte ' B3 is the cell containing the month value. It gives us the destination WORKSHEET Set ws = Worksheets(Range("B3").Value) ' A3 is the cell with the day of the month. It gives us the destination ROW NUMBER ' which we need to increment by 1 to allow for the header row rn = Range("A3").Value + 1 ' Populate a cell in column D of the rn-th row of worksheet ws with the data from ' row 5, column 4 ws.Range("D" & rn).Value = Range("B6")