Excel VBA如何将值视为整数而不是string
我试图让我的脚本把我的价值作为一个整数,而不是一个string。 这是一个查找,从格式化数字单元格获取date。 当我把数据放入工作表时,它充当一个string而不是一个数字。 这是我的代码:
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
如何将Quantity设置为整数,将Price和Total价格设置为货币?
提前致谢。
尝试改变
Cells(NextQuant, 3) = clng(TextBox1.Text)
并添加
Cells(NextPE, 4).NumberFormat = "$#,##0.00" Cells(NextTP, 5).NumberFormat = "$#,##0.00"
什么样的string被返回,你需要什么样的整数?
你可能想要的逻辑号码点数date或date号码,如20150224
如果返回的string类似于"20150224"
,那么使用CInt()
函数就足够了
my_date_int=CInt(dateString)
但是如果它返回一个像"2015-02-24"
这样的string,并且你想要一个整数20150224
你可以使用Format()
my_date_int=CInt(Format(dateString,"yyyyMMdd"))
请在将来更清楚地知道你所得到的input是什么,以及你所期望的输出是什么。