我真的很困惑这个。我知道这可能很简单,但我似乎无法弄明白。我很自豪地创建了一个价格计算器,这是宏观中最重要的部分。
public class arraySort {
public static void main(String[] args) {
int a[] = { 2, 7, 5, 6, 9, 8, 4, 3, 1 };
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if (a[i] < a[j]) {
int temp;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.print("Descending order:{");
StringBuilder br = new StringBuilder();
for (int i = 0; i < a.length; i++) {
br.append(a[i] + ",");
}
System.out.print( br.substring(0, br.length()-1));
System.out.println("}");
}
}
因此MsgBox返回我正在寻找的值,但它被舍入到只有4位小数。我需要更多,但这不是一个大问题,因为单元格然后填充为零,而不是MsgBox中的值。我不知道为什么,考虑到它们都是:
Dim z As Double
For z = 7 To 8 Step 1
If ActiveSheet.Cells(z, 10).Value = "" Then
'''Dim Ref1 As Double
'''Set Ref1 = Sheets("Ref").Cells(o, 4).Value
Dim o As Double
For o = 5 To 150 Step 1
If ActiveSheet.Cells(z, 20).Value = Sheets("Ref").Cells(o, 3).Value Then
MsgBox "Found: " & Sheets("Ref").Cells(o, 4).Value
ActiveSheet.Cells(z, 10).Value = Sheets("Ref").Cells(o, 4).Value
Exit Sub
Else
End If
Next o
Else
End If
Next z
你可以看到我开始为值(Ref1)创建一个Double变量。我认为也许'.Value'在填充单元格时会四舍五入到整数,但是在尝试使用它时我遇到了400错误。
任何帮助将不胜感激!
答案 0 :(得分:-1)
所以我想我以前是在正确的轨道上,我在尝试将Value定义为Double时修正了400错误。这是我最后的工作代码:
'Find Price
Dim z As Long
For z = 7 To 8 Step 1
If ActiveSheet.Cells(z, 10).Value = "" Then
Dim o As Long
For o = 5 To 150 Step 1
If ActiveSheet.Cells(z, 20).Value = Sheets("Ref").Cells(o, 3).Value Then
Dim RefVal As Double
RefVal = Sheets("Ref").Cells(o, 4).Value
ActiveSheet.Cells(z, 10).Value = RefVal
Else
End If
Next o
Else
End If
Next z