Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - Input Box String Length Question

Status
Not open for further replies.

JeffGates

Technical User
May 11, 2002
6
Good evening folks.

Question: Is there a max lenght for the 'String' data type that can be entered by a user into an input box?

Explanation:
I'm trying to load Gift Card Numbers (16 characters each) into an inventory spreadsheet via an input box, code as follows:

Sub InputGiftCard()
Dim NumInput As String
Dim aCell As Range

Set aCell = Range("B65536").End(xlUp)
With aCell
.Offset(1, 0).Value = Date & " " & Time
.Offset(1, 1).Value = Range("GCOpResult")
.Offset(1, 2).Value = Range("GCOpAmt")
.Offset(1, 4).Value = "Active"
End With

NumInput = InputBox(Prompt:="Please Swipe Gift Card", Title:="Enter Gift Card Number")
If NumInput = vbNullString Then
aCell.Offset(1, 0).ClearContents
With aCell
.Offset(1, 1).ClearContents
.Offset(1, 2).ClearContents
.Offset(1, 4).ClearContents
End With
MsgBox ("You must swipe a gift card")
Exit Sub
Else
aCell.Offset(1, 3).Value = NumInput
End If
End Sub

The user can enter a 15 character string with no problem, but if the string exceeds 15 characters each of the additional characters are input into the sheet as zero.

Any suggestions?

 
The issue isn't with a maximum string length returned by the InputBox function, but rather that Excel is interpreting NumImput as a numeric value when entered into the cell (naturally); specifically, a Double floating point value, but precision is lost after 15 digits. To correct this, format the cell as Text before assigning NumImput to it.


Regards,
Mike
 
Thank you Mike. That did the trick. I'm learning VBA as I go and it's always the little things that getcha!

JG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top