Convert a string to a value does not work

most

Board Regular
Joined
Feb 22, 2011
Messages
89
Platform
  1. Windows
  2. Mobile
Why does this not work?
According to the internet I could use Val() to convert a string to a value.

Code:
Sub GotoColumn() Dim x As String
 x = InputBox("Goto column...")
    If IsNumeric(x) = False Then x = Range(x & 1).Column
  x = Val(x)
  Cells(1, x).Activate
End Sub

The script should activate a specific column depending on if you enter a number or a column letter.
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Try:-
Code:
Sub GotoColumn()
Dim x As Variant
 x = InputBox("Goto column...")
    If IsNumeric(x) = False Then
        x = Range(x & 1).Column
    Else
        x = Val(x)
    End If
  Cells(1, x).Activate
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,165
Messages
5,527,187
Members
409,749
Latest member
BorisYeltsin

This Week's Hot Topics

Top