返回列表 上一主題 發帖

如何自動比對數字帶出標準值

本帖最後由 hugh0620 於 2012-4-3 09:19 編輯

回復 1# luke


   用一個最簡單的方式來寫[if]
  1. Sub ex()
  2. For j = 2 To 4 Step 2    '列數,資料要跑第2&4列
  3.      For i = 1 To 10          '欄位從A到J
  4.            If 30.5 < Cells(j, i) And Cells(j, i) <= 40 Then
  5.                Cells(j + 1, i) = 40    '資料放在第3&5列
  6.            ElseIf 25.5 < Cells(j, i) And Cells(j, i) <= 30.5 Then
  7.               Cells(j + 1, i) = 30
  8.            ElseIf 20.5 < Cells(j, i) And Cells(j, i) <= 25.5 Then
  9.               Cells(j + 1, i) = 25
  10.            ElseIf 16.5 < Cells(j, i) And Cells(j, i) <= 20.5 Then
  11.               Cells(j + 1, i) = 20
  12.            ElseIf 12.1 < Cells(j, i) And Cells(j, i) <= 16.5 Then
  13.               Cells(j + 1, i) = 16
  14.            ElseIf 10.1 < Cells(j, i) And Cells(j, i) <= 12.1 Then
  15.               Cells(j + 1, i) = 12
  16.            ElseIf 8.1 < Cells(j, i) And Cells(j, i) <= 10.1 Then
  17.               Cells(j + 1, i) = 10
  18.            ElseIf 6.1 < Cells(j, i) And Cells(j, i) <= 8.1 Then
  19.               Cells(j + 1, i) = 8
  20.            ElseIf 4.1 < Cells(j, i) And Cells(j, i) <= 6.1 Then
  21.               Cells(j + 1, i) = 6
  22.            ElseIf 2# < Cells(j, i) And Cells(j, i) <= 4.1 Then
  23.               Cells(j + 1, i) = 4
  24.            ElseIf 0 < Cells(j, i) And Cells(j, i) <= 2.1 Then
  25.               Cells(j + 1, i) = 2
  26.            End If
  27.      Next
  28. Next
  29. End Sub
複製代碼
學習才能提升自己

TOP

        靜思自在 : 甘願做、歡喜受。
返回列表 上一主題