I want to select a column based on the date in a userform

MRinin

New Member
Joined
Jun 7, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have a schedule for keeping track of hours worked with a list of employees. I have the Userform that pulls up and shows the current date. Along the top of my excel sheet I have the dates. I want to populate the hours worked in the column of the date shown in the textbox of the userform.

So I have:

Private Sub UserForm_Initialize()
Me.TextBox11.Value = Format(Date, "mm/dd/yy")
End Sub

'This populates the date in my text box'

My form looks like this:
1623113450968.png


My sheet looks like this:
1623113523972.png


Help please.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
How would I code that? (Pardon my ignorance, but I am self google taught in the world of VBA)
 
Upvote 0
1623127829067.png

There is no name to the table and the range is just selected by the headings. I want to be able to send the data to the column that has the same date as the form.
 

Attachments

  • 1623127757029.png
    1623127757029.png
    54.8 KB · Views: 6
Upvote 0
Disclaimer: I am google taught as well and had pieced this together honestly as a bit of a challenge. Maybe not the best way or fastest but try it and adapt to your needs. let me know if it does help.

VBA Code:
Dim findDate As Date
findDate = TextBox1.Value
Dim R As Range, C As Range, WS As Worksheet
Dim LastCol As Integer, i As Integer, rng As Range

Set WS = Worksheets("Sheet1") 'Change this to your sheet name
LastCol = WS.Cells(2, WS.Columns.Count).End(xlToLeft).Column 'Finds all columns in Row 2
  Debug.Print LastCol 'check this to make sure all is working
    For i = 1 To LastCol
        Set R = Cells(2, i)

For Each C In R
    If C.Value2 = CDbl(findDate) Then
    MsgBox findDate & "found in " & C.Address    ' or use C.Offset(1, 0).Address to select parts of the column or continue from here
    End If
    Next
    Next
End Sub

You can use for example C.Offset(5,0).Value = TextboxHoliday.value "Just random example" instead of the MsgBox
 
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

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