2016-06-22 84 views
0

我將值賦給三個單元格(inspecao,alpha和lambda)。 此代碼適用於分配的整數數字,但不適用於小數。使用Application.InputBox粘貼十進制值

對於< 1個數字或小數,Excel寫入0。

Dim alpha as Double 
Dim inspecao As Double 
Dim lambda As Double 

inspecao = CInt(Application.InputBox("Insira o intervalo de inspecao:", Type:=1)) 
alpha = CInt(Application.InputBox("Insira o parametro alpha:", Type:=1)) 
lambda = CInt(Application.InputBox("Insira o parametro lambda:", Type:=1)) 

Range("E1").Value = inspecao 
Range("I2").Value = alpha 
Range("L1").Value = lambda 

回答

1

Weber,那是因爲你正在鑄造一切爲CInt。只要刪除,你會沒事的:

Dim alpha As Double 
    Dim inspecao As Double 
    Dim lambda As Double 

    inspecao = Application.InputBox("Insira o intervalo de inspecao:", Type:=1) 
    alpha = Application.InputBox("Insira o parametro alpha:", Type:=1) 
    lambda = Application.InputBox("Insira o parametro lambda:", Type:=1) 

    Range("E1").Value = inspecao 
    Range("I2").Value = alpha 
    Range("L1").Value = lambda 
+0

很久以前從一個網站複製了這部分代碼,甚至沒有看得更遠!哈哈謝謝。 – m3dl

+0

我的榮幸!祝你的項目好運! –