Link to home
Start Free TrialLog in
Avatar of NewBieSteffie
NewBieSteffieFlag for Philippines

asked on

How can I set the range using the users column letter input?

The user can input a column letter

How can I set the range if the user has already inputted a column letter
I have pasted my code here in which I set the range to the column letter that the user inputted up to its last row

Dim IntColumn
    
     ColumnLetter = Application.InputBox(prompt:="Enter Column Letter ", Type:=2)
    
    With ActiveSheet
     LastRow = .Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
    End With
    
    Set IntColumn = Range("ColumnLetter:LastRow")
    

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try:

Set IntColumn = Range(ColumnLetter & ":" & LastRow)

Open in new window

Avatar of NewBieSteffie

ASKER

I got a run time error 1004

What should I do?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When you have separate Column and Row variables, I generally find it easier to use and understand if I use the Cells method...

Set IntColumn = Cells(RowIndex:=LastRow, ColumnIndex:=ColumnLetter)

Open in new window


Note that ColumnIndex accepts either numbers or string (text) representations.
This works !!!
Thanks
@Ryan Chong Thank you!
@Wayne Taylor (webtubbs)
Your code works as well thank you