vba to find a date in a range to upload the userform data into that row

bigbertha98

New Member
Joined
Jan 2, 2019
Messages
2
I am having a bit of a headache and I've found this forum very useful in the past however I can't find a clear answer for this one anywhere. Apologies I am a novice at this so please bear with me.
I have put together a userform and a spreadsheet for it to be uploaded into. The problem I have is I want the data in the userform to look at the date in a textbox and find the corresponding row where that date occurs. Then I want it to upload the data into that row and for this all to be done on the click of a command button.

The spreadsheet has a list of dates in column A between A3 and A370 going from 01/04/18 to 31/03/19 (one date per day)
The code needs to look in this range, find the date and upload the data held in the userform into that specific row.

Unfortunately due to admin restrictions I am unable to upload an screenshots which would make it much easier
Here is the Sub I’m working with and I can’t join the search and upload elements

Code:
Sub Dataentry()

Dim Found As Range
Set Found = Sheets("CST Productivity").Range("A3:A370").Find(What:=Me.TextBox17.Value, _
                                                        LookIn:=xlValues, _
                                                        LookAt:=xlByRows, _
                                                        SearchOrder:=xlByRows, _
                                                        SearchDirection:=xlNext, _
                                                        MatchCase:=False)

    

               
        
            If Found Is Nothing Then
            MsgBox "Date Not Present on Tracker"
            'Exit Sub
            Else: Found.Select
            End If

''Dim wb As Workbook
''Set wb = ThisWorkbook
''Dim ws As Worksheet
''Dim NextRow As Long
''Set ws = wb.Sheets("CST Productivity")
''NextRow = ws.Range("B" & Rows.Count).End(xlUp).Row + 1
'With Sheets("CST Productivity")
'NextRow = .Range("B" & Rows.Count).End(xlUp).Row + 1
'
'
''CST1:
'.Range("B" & NextRow) = 7.4
'.Range("B" & NextRow).Offset(0, 1).Value = UserForm1.TextBox98.Value
'.Range("B" & NextRow).Offset(0, 2).Value = UserForm1.TextBox147.Value
'.Range("B" & NextRow).Offset(0, 3).Value = UserForm1.TextBox146.Value
'.Range("B" & NextRow).Offset(0, 4).Value = UserForm1.TextBox148.Value
'.Range("B" & NextRow).Offset(0, 5).Value = UserForm1.TextBox114.Value
'.Range("B" & NextRow).Offset(0, 6).Value = UserForm1.TextBox66.Value
'.Range("B" & NextRow).Offset(0, 7).Value = UserForm1.TextBox82.Value
'.Range("B" & NextRow).Offset(0, 8).Value = UserForm1.ComboBox95.Text
'.Range("B" & NextRow).Offset(0, 9).Value = UserForm1.ComboBox1.Text
'.Range("B" & NextRow).Offset(0, 10).Value = UserForm1.ComboBox18.Text
'.Range("B" & NextRow).Offset(0, 11).Value = UserForm1.TextBox130.Text
'.Range("B" & NextRow).Offset(0, 12).Value = UserForm1.ComboBox33.Text
'.Range("B" & NextRow).Offset(0, 13).Value = UserForm1.ComboBox79.Text
'.Range("B" & NextRow).Offset(0, 14).Value = UserForm1.TextBox269.Text
 
Last edited by a moderator:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi & welcome to MrExcel.
Try
Code:
.Find(CDate(Me.TextBox1.Value)
 
Upvote 0
Hi & welcome to MrExcel.
Try
Code:
.Find(CDate(Me.TextBox1.Value)

Thanks for the welcome and the quick response. The findelement of the code appears to be working correctly (probably as it uses thecode you suggested) however the bit im struggling with is when the code findsthe date and the row it sits in, I cant get it to move the data from theuserform to the found row. I’ve copied an extract from the table to explain thisbetter which will hopefully come through.

Book1
AB
1Look for the date in Range A3:A367
21/4/2018
32/4/2018
43/4/2018
54/4/2018
65/4/2018
76/4/2018
87/4/2018
98/4/2018
109/4/2018
1110/4/2018
1211/4/2018
1312/4/2018
1413/4/2018
1514/4/2018
1615/4/2018
1716/4/2018
1817/4/2018
1918/4/2018
2019/4/2018
2120/4/2018
2221/4/2018
2322/4/2018
2423/4/2018
2524/4/2018When the date is found say for example "23/04/2018", move the data from e userform into ow 25 next to the found date
2625/4/2018
2726/4/2018
2827/4/2018
2928/4/2018
3029/4/2018
Sheet1
 
Last edited by a moderator:
Upvote 0
Change this code to use the row of Found.
Code:
''CST1:
'.Range("B" & NextRow) = 7.4
'.Range("B" & NextRow).Offset(0, 1).Value = UserForm1.TextBox98.Value
'.Range("B" & NextRow).Offset(0, 2).Value = UserForm1.TextBox147.Value
'.Range("B" & NextRow).Offset(0, 3).Value = UserForm1.TextBox146.Value
'.Range("B" & NextRow).Offset(0, 4).Value = UserForm1.TextBox148.Value
'.Range("B" & NextRow).Offset(0, 5).Value = UserForm1.TextBox114.Value
'.Range("B" & NextRow).Offset(0, 6).Value = UserForm1.TextBox66.Value
'.Range("B" & NextRow).Offset(0, 7).Value = UserForm1.TextBox82.Value
'.Range("B" & NextRow).Offset(0, 8).Value = UserForm1.ComboBox95.Text
'.Range("B" & NextRow).Offset(0, 9).Value = UserForm1.ComboBox1.Text
'.Range("B" & NextRow).Offset(0, 10).Value = UserForm1.ComboBox18.Text
'.Range("B" & NextRow).Offset(0, 11).Value = UserForm1.TextBox130.Text
'.Range("B" & NextRow).Offset(0, 12).Value = UserForm1.ComboBox33.Text
'.Range("B" & NextRow).Offset(0, 13).Value = UserForm1.ComboBox79.Text
'.Range("B" & NextRow).Offset(0, 14).Value = UserForm1.TextBox269.Text
For example.
Code:
.Range("B" & Found.Row).Offset(0, 1).Value = UserForm1.TextBox98.Value
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top