返回列表 上一主題 發帖

[發問] 關於使用錄製巨集編修程式碼--->"無資料則跳過"

如下試試

Sub 轉置()
Sheet1.[J3:N65536].ClearContents
X = Sheet1.[B65536].End(xlUp).Row
Y1 = Sheet1.[J65536].End(xlUp).Row
Y2 = Sheet1.[K65536].End(xlUp).Row
Y3 = Sheet1.[L65536].End(xlUp).Row
Y4 = Sheet1.[M65536].End(xlUp).Row
Y5 = Sheet1.[N65536].End(xlUp).Row
For M = 3 To X
If Sheet1.Cells(M, 3) = "一" Then
   Sheet1.Cells(Y1 + 1, 10) = Sheet1.Cells(M, 2)
   Y1 = Y1 + 1
End If
If Sheet1.Cells(M, 3) = "二" Then
   Sheet1.Cells(Y2 + 1, 11) = Sheet1.Cells(M, 2)
   Y2 = Y2 + 1
End If
If Sheet1.Cells(M, 3) = "三" Then
   Sheet1.Cells(Y3 + 1, 12) = Sheet1.Cells(M, 2)
   Y3 = Y3 + 1
End If
If Sheet1.Cells(M, 3) = "四" Then
   Sheet1.Cells(Y4 + 1, 13) = Sheet1.Cells(M, 2)
   Y4 = Y4 + 1
End If
If Sheet1.Cells(M, 3) = "五" Then
   Sheet1.Cells(Y5 + 1, 14) = Sheet1.Cells(M, 2)
   Y5 = Y5 + 1
End If
  Next
End Sub
羅

TOP

        靜思自在 : 不要小看自己,因為人有無限的可能。
返回列表 上一主題