scanning in UPC's ... How to get them entered as a string (text)

instanceoftime

Board Regular
Joined
Mar 23, 2011
Messages
69
I have the following code ... works fine but at times it drops the leading zero when placing it in a cell.
I have the cells formatted as text as well but doesn't seem to change things.
how can I make sure the cell is written to as text?


Code:
Sub FillUPCNumber()


    Dim arr1 As Variant
    Dim ii As Long
    Dim str9 As String, str10 As String, str11 As String, str12 As String, str13 As String, str14 As String, str15 As String, str16 As String
    Dim Response2 As String
    Dim Response3 As Variant
    
    ii = 0
    
    ActiveWorkbook.Sheets("Items").Activate
    
    With ActiveSheet
        arr1 = .Range("A1:H" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    End With


    For ii = 1 To UBound(arr1)
        If arr1(ii, 1) = GetItemNumber Then
            str9 = IIf(str9 = "", arr1(ii, 1), str9 & " " & arr1(ii, 1)) 'item number
            str10 = IIf(str10 = "", arr1(ii, 2), str10 & " " & arr1(ii, 2)) 'description
            str11 = IIf(str11 = "", arr1(ii, 3), str11 & " " & arr1(ii, 3)) 'id
            str12 = IIf(str12 = "", arr1(ii, 4), str12 & " " & arr1(ii, 4)) 'date
            str13 = IIf(str13 = "", arr1(ii, 5), str13 & " " & arr1(ii, 5)) 'dept#
            str14 = IIf(str14 = "", arr1(ii, 6), str14 & " " & arr1(ii, 6)) 'dept
[COLOR=#ff0000]            str15 = IIf(str15 = "", arr1(ii, 7), str15 & " " & arr1(ii, 7)) 'upc[/COLOR]
            str16 = IIf(str16 = "", arr1(ii, 8), str16 & " " & arr1(ii, 8)) 'price
            If Cells(ii, 7).Value = "" Then
[COLOR=#ff0000]                Cells(ii, 7).Value = UPCNumber[/COLOR]
                Cells(ii, 8).Value = GetPrice
            End If
            If Cells(ii, 5).Value = "" Then
                Cells(ii, 5).Value = GetDeptNum
                Cells(ii, 6).Value = GetDepartment
            End If
        End If
    Next
                    


    
End Sub
 

RickXL

MrExcel MVP
Joined
Sep 9, 2013
Messages
4,314
Hi,

Try adding a single quote to the start:
Code:
Cells(ii, 7).Value = "'" & upc
(That's a single quote surrounded by a pair of double quotes.)


Regards,
 

Forum statistics

Threads
1,078,461
Messages
5,340,440
Members
399,375
Latest member
alwayssunny

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top