+ Reply to Thread
Results 1 to 3 of 3

unexpected result from inputbox

  1. #1
    HRman
    Guest

    unexpected result from inputbox

    Hi,

    I have a piece of code that promts for an employee number which may or may
    not have a leading zero. If I print out the employee number using msgbox it
    has the leading zero, but when i place it on a worksheet, the leading zero
    disappears.

    dim empno as string

    empno = inputbox("enter the employee number")
    msgbox ">"+empno+"<"
    worksheets("sheet1").cells(1,2).value = empno


    Any suggestions ?

  2. #2
    Toppers
    Guest

    RE: unexpected result from inputbox

    Hi,
    Cell must be defined as Text not General - try the following :

    Dim empno As String

    empno = InputBox("enter the employee number")

    Worksheets("sheet1").Cells(1, 2).NumberFormat = "@"
    Worksheets("sheet1").Cells(1, 2).Value = empno

    "HRman" wrote:

    > Hi,
    >
    > I have a piece of code that promts for an employee number which may or may
    > not have a leading zero. If I print out the employee number using msgbox it
    > has the leading zero, but when i place it on a worksheet, the leading zero
    > disappears.
    >
    > dim empno as string
    >
    > empno = inputbox("enter the employee number")
    > msgbox ">"+empno+"<"
    > worksheets("sheet1").cells(1,2).value = empno
    >
    >
    > Any suggestions ?


  3. #3
    Kris
    Guest

    Re: unexpected result from inputbox

    HRman wrote:
    > Hi,
    >
    > I have a piece of code that promts for an employee number which may or may
    > not have a leading zero. If I print out the employee number using msgbox it
    > has the leading zero, but when i place it on a worksheet, the leading zero
    > disappears.
    >
    > dim empno as string
    >
    > empno = inputbox("enter the employee number")
    > msgbox ">"+empno+"<"
    > worksheets("sheet1").cells(1,2).value = empno
    >
    >
    > Any suggestions ?


    Because Execel treats your result as a number and cuts leading zeros.

    worksheets("sheet1").cells(1,2).value = "'" & empno



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1