相对循环迭代计数

我正在使用Excel来格式化.csv文件的输出,该文件创build几个“块”的数据,但都是相对于相同的时间戳。 为了使用这些数据,我必须格式化,使得时间戳记在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 

从MSDN的库中查看关于For语句的这个页面。

你可以做这样的事情:

 For loop_ctr = 1 To n '' Do stuff here, like nest another For Loop Next 

让我知道这是否需要进一步解释。