InputBox value being assigned as date rather then string

sparky2205

Active Member
Joined
Feb 6, 2013
Messages
480
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi folks,
I have a macro that takes an entry from an inputbox and assigns it to variable a of type variant.
A problem arises when the entry in the inputbox is similar to a date. e.g. if the value from the inputbox is FEB02. This is not a date, it just happens to resemble a date.
When analysing the code, variable a has the value "FEB02" which is what I want. But when I assign this value to a cell it gets assigned as 02-Feb.
I've tried changing the data type to String, to no effect. But I would prefer to leave it as variant anyway as it causes other issues later if the type is string.
I've also tried using CStr(a) when assigning the value, to no effect.

This is my inputbox:
Code:
a = Application.InputBox("Enter the new Vendor Number", , , , , , , 2)

This is my value assignment:
Code:
Selection.Value = a

Any ideas what I'm doing wrong?

Thanks.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Excel is being overly helpful. The assign-value-to-cell routine is reading that as a date rather than a string. Try


Code:
Selection.Value = "'" & a

or, if you do need numeric entry sometimes, this

Code:
If IsNumeric(a) then
    Selection.Value = a
Else
    Selection.Value = "'" & a
End If
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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