VBA Place value as number into cell

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Private Sub CommandButton1_Click()
Dim LastRow As Long, ws As Worksheet
If Not IsNumeric(TextBox1.Value) = Format(TextBox1.Value, "") = True Or TextBox1.Value = vbNullString Or Len(TextBox1.Value) <> 5 Then
    MsgBox "ENTER 5 DIGIT ASSET TAG NUMBER"

Else
LastRow = Sheets("SCANNERS").Range("A" & Rows.Count).End(xlUp).Row + 1
    With ActiveSheet
        .Range("A" & LastRow).Value = TextBox1
        .Range("C" & LastRow).Value = TextBox2
    End With
End If
End Sub

Using the above VBA it seems to place the value in textbox1 as a text value and not number.

because in cell B I have the Following formula:
Defective Scanner Tracker.xlsm
B
2 
SCANNERS
Cell Formulas
RangeFormula
B2B2=IFERROR(INDEX(INV!$B$2:$B$1001,MATCH(A2,INV!$A$2:$A$1001,0)),"")


Defective Scanner Tracker.xlsm
AB
1BARCODE#SERIAL NUMBER
213383S20312522501204
313204S19266522500480
INV


so if textbox 1 is 13204 and its placed in column "A" the Seral number does not appear until after I double click the cell and hit enter. any suggestions with this.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
TextBoxes contain Text, not numbers, so you need to convert it
VBA Code:
.Range("A" & LastRow).Value = Val(TextBox1)
 
Upvote 0
Solution

Forum statistics

Threads
1,214,515
Messages
6,119,969
Members
448,933
Latest member
Bluedbw

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