User Form text box value to select column

ikjohnson

Board Regular
Joined
Sep 19, 2003
Messages
133
Hi,

How could an entry in a text box on a user form be used to select a column?
For example, if "T" (without quotes) is entered in a text box, and a command button is clicked, column T is selected. Something like:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()<br><br><SPAN style="color:#007F00">' Code here to retrieve value of text box in order to select column</SPAN><br> Columns("T:T").Select<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Dim res As String
res = TextBox1.Text
On Error GoTo errhandler
ActiveSheet.Columns(res).Select
Exit Sub
errhandler:
MsgBox "You can enter a Column LETTER Only"
 
Upvote 0
Jim,

Thank you; just what I wanted.
I also tested the error handling, and an entry such as "T,W" (without quotes) triggers the message box, while an entry such as "T:W" selects columns T to W.
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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