1
我正在使用Excel來格式化.csv文件的輸出,該文件創建幾個「塊」數據,但都是相對於相同的時間戳。爲了使用這些數據,我必須格式化,使時間戳記在B列中,然後將數據重新定位到其右側的列中。我需要循環相同的代碼行次數(n),但我需要嵌套循環(s)爲每個循環迭代循環(n + 1)次。相對循環迭代計數
Sub Format Data()
Dim n as Integer
loop_ctr = 1
Do
' Create Header Data For Channel 1
' Find CH# and use offset commands to select and copy pertinent channel label and data information
'
' Set cursor to Cell A1
Sheets("Raw Data Input").Select
Range("A1:A1").Select
'Finds first instance of CH#, which will be used as an anchor cell for copying and pasting relevant channel information into the formatted data spreadsheet.
loop_ctr = 1
Do
Cells.Find(What:="CH#", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
loop_ctr = loop_ctr + 1
Loop While loop_ctr < n
'Offset command to select cell containing Channel Name,set the variable type to string (to allow units
'and measurement type to be appended to the channel name for data table header.
'Get Channel Name
ActiveCell.Offset(1, 1).Select
Selection.Copy
Sheets("Formatted Data Output").Select
Sheets("Formatted Data Output").Range("1:1").End(xlToRight).Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Loop_ctr = loop_ctr + 1 = n
Loop While n <13
End Sub
你能告訴我們一個輸入數據的例子,以及對於那些想要的輸出嗎? –
不能超過註釋char限制;-) – HumanoidTyphoon
嗯,你可以隨時編輯你的問題 –