PDA

View Full Version : Using Input Box Variable



Jenst
09-21-2016, 05:35 AM
Hi, Does anyone has an idea, why I`m getting an error?? The input box is generating a number


Code:

dim exps as variant
dim Num as integer

exps = InputBox("Please input Experience column")
Num = Range(Cells(3, exps), Cells(3, exps).End(xlDown)).Count



Error:
Run-time error 1004
Application-defined or object-defined error

Thanks!! Jens

Paul_Hossler
09-21-2016, 06:38 AM
Used that way, InputBox returns a string that only looks like a number

Cells expects a 'real' number

So us CLng() to make it a real Long number




Option Explicit
Sub test()
Dim exps As Variant
Dim Num As Integer

exps = InputBox("Please input Experience column")
exps = CLng(exps)
Num = Range(Cells(3, exps), Cells(3, exps).End(xlDown)).Count
End Sub

Jenst
09-21-2016, 09:12 AM
Thanks for giving me exactly the information that I needed. Really helpful, works now!:hi:

Kenneth Hobs
09-21-2016, 01:23 PM
fwiw


Sub Main()
Dim exps As Variant
Dim Num As Integer

exps = Application.InputBox("Please input Experience column", Type:=1)
Num = Range(Cells(3, exps), Cells(3, exps).End(xlDown)).Count
End Sub