返回列表 上一主題 發帖

IF...判斷加總問題

請用錄製巨集方式再來修改範圍
  1. Sub 巨集3()
  2.     Range("G1").Select
  3.     ActiveCell.FormulaR1C1 = "=IF(RC[-4]="""","""",RC[-4]+RC[-1])"
  4.     Range("G1").Select
  5.     Selection.AutoFill Destination:=Range("G1:G4"), Type:=xlFillDefault
  6.     Range("G1:G4").Select
  7. End Sub
複製代碼
把範圍G4改變數
x=[C65536].end(xlup).Row
Range("G1:G" & x)
  1. Sub 巨集3()
  2. Dim x As Integer
  3.     x = [C65536].End(xlUp).Row
  4.     Range("G1").FormulaR1C1 = "=IF(RC[-4]="""","""",RC[-4]+RC[-1])"
  5.     Range("G1").AutoFill Destination:=Range("G1:G" & x), Type:=xlFillDefault
  6. End Sub
複製代碼

TOP

用錄製了解程序再來修改或是直接使用
  1. Sub test()
  2. For i = 1 To [C65536].End(xlUp).Row
  3.     If Cells(i, 3) = "" Then
  4.         Cells(i, 7) = ""
  5.     Else
  6.         Cells(i, 7) = Cells(i, 3) + Cells(i, 6)
  7.         Cells(i, 7).Font.Color = vbBlue
  8.         Cells(i, 7).Font.Bold = True
  9.     End If
  10. Next
  11. End Sub
複製代碼

TOP

        靜思自在 : 欣賞別人就是莊嚴自己。
返回列表 上一主題