select range inputbox

Urraco

Board Regular
Joined
Apr 19, 2021
Messages
68
Office Version
  1. 2016
Platform
  1. Windows
how can I select from cell A1 to "input user".. ex. H1

1628690229104.png



this not work

VBA Code:
Sub teeest()
Dim x As Variant
x = InputBox("column?")
Range("A1", x).Select
End Sub

thankyou
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Like this:
VBA Code:
Sub teeest()
Dim x As Variant
x = InputBox("column?")
Range("A1:" & x & "1").Select
End Sub
 
Upvote 0
Solution
What exactly are you entering into the Input Box?

Since you have the input box say "Column?", I was assuming that you are only entering the column letter (i.e. "H").

If you are entering the actually full address (i.e. "H1") of the last cell you want, and not just the column, then use this variation:
VBA Code:
Sub teeest()
Dim x As Variant
x = InputBox("address?")
Range("A1:" & x).Select
End Sub
 
Upvote 0
still error

1628773231745.png


I want to select from column A1 "which is the default" to column H or column 8
ex. Range("A1:H1").Select
 
Upvote 0
If you are just entering in the column letter ("H"), then the first code I posted up in my first reply should work.

If it does not, then please answer the following questions:
1. Are you getting any error messages? If so, what do they say?
2. If there are no error messages, but it just isn't doing what you want, please explain what it is doing?
3. Is column H or row 1 protected?
4. Are any of the cells in the range A1:H1 part of merged cells?
5. Is column H or row 1 hidden?
 
Upvote 0
You could do something like this?

VBA Code:
Sub teeest()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select last cell", Type:=8)
On Error GoTo 0
If Not x Is Nothing Then Range("A1", x).Select
End Sub
 
Upvote 0
If you are just entering in the column letter ("H"), then the first code I posted up in my first reply should work.

If it does not, then please answer the following questions:
1. Are you getting any error messages? If so, what do they say?
2. If there are no error messages, but it just isn't doing what you want, please explain what it is doing?
3. Is column H or row 1 protected?
4. Are any of the cells in the range A1:H1 part of merged cells?
5. Is column H or row 1 hidden?
now I see that it works, yesterday I tried several times and it didn't work ... I don't know ...
thank you

Code:
Sub teeest()
Dim x As Variant
x = InputBox("column?")
Range("A1:" & x & "1").Select
End Sub
 
Upvote 0
That's good too..(y)


You could do something like this?

VBA Code:
Sub teeest()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select last cell", Type:=8)
On Error GoTo 0
If Not x Is Nothing Then Range("A1", x).Select
End Sub
 
Upvote 0
Glad you got it sorted out.
Rory's option is a nice one, as in selecting the cell, it reduces the possibility on key entry errors.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,039
Members
449,063
Latest member
ak94

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