Excel 中 VBA中運行這段 Do While Range("A1:A65536") <> "" 時 提示運行錯誤'13' 型別不匹配 是什么意思呢?
意圖:比較第i行的 單元格Bi 到 Ei 的值,找出最大值,然后根據得出的最大值的單元格代表的意義,將結果寫在Fi 和 Gi 單元格上。
貼上原代碼:
Sub 比較取狀態自動()
Do While Range("A1:A65536") <> "" '當A列單元格不等于空時,回圈獲取狀態
Dim i&
For i = 2 To 65536
If Cells(i, "b") > Cells(i, "c") And Cells(i, "b") > Cells(i, "d") And Cells(i, "b") > Cells(i, "e") Then
Cells(i, 6) = "Bornege" '輸出最大的值B,結果顯示在F、G
Cells(i, 7) = "2OnCutDown"
Else
If Cells(i, "c") > Cells(i, "d") And Cells(i, "c") > Cells(i, "e") Then
Cells(i, 6) = "PutIn" '輸出最大的值C,結果顯示在F、G
Cells(i, 7) = "1OnBorn" 'C>E輸出C
Else
If Cells(i, "d") > Cells(i, "e") Then
Cells(i, 6) = "Seach" '輸出最大的值D,結果顯示在F、G
Cells(i, 7) = "0OnPutIn" 'D>E時 直接輸出最大的值D,結果顯示在F、G
Else
Cells(i, 6) = "CutDown" '輸出最大的值E,結果顯示在F、G
Cells(i, 7) = "0OnPutIn"
End If
End If
End If
Next i
Loop
End Sub
按F8時運行到Do While時就報錯了,請問各位大神是什么意思呢?怎么破
uj5u.com熱心網友回復:
1、Range("A1:A65536") 是一個range集合,當然不能和字串進行比較。怎么破?
for i=1 to 65536
if cells(i,1)="" then exit for
''獲取最大值
next
2、你后面的代碼也有問題。你最好查查worksheetfunction,里面有一個max函式
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/76819.html
標籤:VBA
