Select Range of Cells Based on UserForm Input Value

Drogan

New Member
Joined
Mar 1, 2011
Messages
32
So I'm creating a UserForm that takes user input to create a worksheet based on the values input. My question is: How to select a range of cells based on a variable input value? For example, it asks how many competitors there are, and the user can input 5, 8, 10, etc. So I want that many cells in Row 1 selected, whatever the value input is. Thank you.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Code:
Sub Vrange()
Dim cl
    cl = InputBox("How many competitors?", "THIS MANY")
    Range("A1").Resize(, cl).Select
End Sub
 
Upvote 0
Ok, the InputBox is all well and good, but the thing is, I have a multiple field UserForm. So I need it to be pulled directly from the UserForm without having to use any extra input boxes separate from the UserForm. Is there a way to do that?
 
Upvote 0
Try this.
Code:
Dim NoCompetitors As Long

     NoCompetitors = Val(Textbox1.Value)

     Worksheets("Sheet1").Range("A1").Resize(NoCompetitors).Select
 
Upvote 0
Thanks Norie, but unfortunately it gives me a type mismatch error. Is there something I'm missing?
 
Upvote 0
What did you enter in the textbox?
 
Upvote 0
Well, the number of competitors, of course: 8, 10, 15... But it won't select the cells and gives me the Type Mismatch error.
 
Upvote 0
It works for me.

What exact code did you use?
 
Upvote 0
The one you posted. I even tried a couple different variations. Here's the code I have:

Code:
Private Sub CommandButton1_Click()

Dim NoCom As Long

     'Number of Competitors
     NoCom = Val(TextBox1.Value)

'Select the range for number of competitors
Sheets(Sheet1).Range("A1").Resize(NoCom).Select

UserForm1.Hide

End Sub
 
Upvote 0
That's not the same as the code I posted, this part is completely different.
Code:
Sheets(Sheet1)
 
Upvote 0

Forum statistics

Threads
1,214,547
Messages
6,120,139
Members
448,948
Latest member
spamiki

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