我有一串數據 ,想轉成可以用樞紐方式分析 ,但有需要先轉成下面如圖所示嗎?!
有需要
執行 VBA 前
執行 VBA
執行後結果
海大大 ,可以參考下面新的條件嗎?
程式碼如下
Option Explicit
Const mainSheetName = "Report"
Const dataSheetName = "Raw"
Sub Main()
Dim sComponent, sNumber, sColumn, sRow, sCenterX, sCenterY, sFocus As String
Dim bFirst As Boolean
bFirst = True
Sheets(mainSheetName).Select
Range("C1").Select
Do While ActiveCell <> ""
If ActiveCell.Value = "ShotNo" Then
If bFirst = True Then
bFirst = False
Else
Call SaveOneRecord(sComponent, sNumber, sColumn, sRow, sCenterX, sCenterY, sFocus)
End If
sNumber = ActiveCell.Offset(0, 1)
ElseIf ActiveCell.Value = "WaferNo" Then
Call SaveOneRecord(sComponent, sNumber, sColumn, sRow, sCenterX, sCenterY, sFocus)
bFirst = True
sComponent = ActiveCell.Offset(0, 1)
ElseIf ActiveCell.Value = "Row" Then
sColumn = ActiveCell.Offset(0, 1)
sRow = ActiveCell.Offset(0, 3)
ElseIf ActiveCell.Value = "ShotCentX" Then
sCenterX = ActiveCell.Offset(0, 1)
sCenterY = ActiveCell.Offset(0, 3)
ElseIf ActiveCell.Value = "Last" Then
sFocus = ActiveCell.Offset(0, 2)
End If
ActiveCell.Offset(1, 0).Select
Loop
Call SaveOneRecord(sComponent, sNumber, sColumn, sRow, sCenterX, sCenterY, sFocus)
End Sub
Sub SaveOneRecord(ByVal pComponent, ByVal pNumber, ByVal pColumn, ByVal pRow, ByVal pCenterX, ByVal pCenterY, ByVal pFocus)
Sheets(dataSheetName).Select
Range("A10000").End(xlUp).Offset(1, 0).Select
ActiveCell.Offset(0, 0).Value = pComponent
ActiveCell.Offset(0, 1).Value = pNumber
ActiveCell.Offset(0, 2).Value = pColumn
ActiveCell.Offset(0, 3).Value = pRow
ActiveCell.Offset(0, 4).Value = pCenterX
ActiveCell.Offset(0, 5).Value = pCenterY
ActiveCell.Offset(0, 6).Value = pFocus
Sheets(mainSheetName).Select
End Sub