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

instanceoftime

Board Regular
Joined
Mar 23, 2011
Messages
102
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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,488
Members
448,967
Latest member
visheshkotha

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