mardi 24 février 2015

Exel VBA how to treat value as a integer rather than as a string

I am trying to get y script to treat my value as a interger rather than a string. It is a vlookup, that gets the date from a formatted number cell. When I put the data into the sheet though, it acts as a string and not a number. Here is my code:



Private Sub CommandButton1_Click()

Dim NextProd As Long
Dim NextPC As Long
Dim NextQuant As Long
Dim NextPE As Long
Dim NextTP As Long

NextProd = Cells(Rows.Count, "A").End(xlUp).Row + 1
NextPC = Cells(Rows.Count, "B").End(xlUp).Row + 1
NextQuant = Cells(Rows.Count, "C").End(xlUp).Row + 1
NextPE = Cells(Rows.Count, "D").End(xlUp).Row + 1
NextTP = Cells(Rows.Count, "E").End(xlUp).Row + 1

Dim lookupRange As Range
Set lookupRange = Worksheets("Products").Range("A1:C1679")
Dim Products As Range
Set Products = Worksheets("Products").Range("A1:B1679")
Dim Description As Range
Set Descrpition = Worksheets("products").Range("A1:A1679")

ItemPrice = Application.VLookup(InvoiceProductEntry.Selectprodcutcombo.Value, lookupRange, 3, False)
ProductCode = Application.VLookup(InvoiceProductEntry.Selectprodcutcombo.Value, lookupRange, 2, False)
ProductDescription = Application.VLookup(InvoiceProductEntry.Selectprodcutcombo.Value, lookupRange, 1, False)

Totalprice = TextBox1.Value * ItemPrice

Cells(NextProd, 1) = Selectprodcutcombo.Value
Cells(NextPC, 2) = ProductCode
Cells(NextQuant, 3) = TextBox1.Text
Cells(NextPE, 4) = ItemPrice
Cells(NextTP, 5) = Totalprice

End Sub


How can I set the Quantity as a integer and the Price each and Total price as a currency?


Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire