View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
fisch4bill fisch4bill is offline
external usenet poster
 
Posts: 43
Default Select column that matches a value entered in a User Form TextBox

Hi Gwyzor,

The following code may get you on the right track. It is a simple macro that
asks the user to specify the day of the month, and then activates the cell in
the appropriate column just below the last used cell. With this particular
code, you don't even have to have header values that correspond to the days
of the months. Regardless of what's in the first row, this code will select
the appropriate column:

'code starts:

Sub SelectColumn()
Dim DayNum As Integer
DayNum = InputBox("Please input today's" & vbNewLine & "day of the month")
Cells(Cells(Rows.Count, DayNum).End(xlUp).Row + 1, DayNum).Activate
End Sub

'code ends

HTH

"Gwyzor" wrote:

I am building an Excel 2007 User Form in VB. I want my users to be able to
type the day of month (i.e. 6 for the 6th of the month) and have code that
automatically selects the column that is set up for that date to be used.
Each column has the day of the month as the top field of the column.
Therefore, if they type '6', I want to select the equal value, '6' in the day
column, and use that column. Have tried several functions, and am not coming
up with the correct code to accomplish this.