這應該做你正在尋找做,如果我理解你的原來的職位,我可能沒有什麼。有關您的牀單佈局的更多細節將有所幫助。這個概念可能是足夠的,雖然教你你正在尋找什麼。查看提供的截圖以瞭解佈局。
在此示例中,您已經創建了目標工作表。你只需要作標題行,並命名錶,然後當你聲明變量newSheet =「您命名該工作表」,在這個例子中,它是「TargetSheet」
Sub mymacro()
'Declare the counters as Integers, not byte
Dim oRow As Integer
Dim i As Integer
Dim LastRow As Integer
Dim LastNewRow As Integer
Dim newSheet As String
Dim nRow As String
Dim n As Integer
Dim LastNCol As Integer
Dim searchString As String
'Not Sure what kind of value the N points are.
Dim Value As String
'The original sheet is Sheets("laos"
'If you don't need to create the new Worksheet every time, just declare it.
newSheet = "TargetSheet"
'set LastRow using by specifying the sheet and range to search.
LastRow = Sheets("laos").Range("A65536").End(xlUp).Row
LastNewRow = Sheets(newSheet).Range("A65536").End(xlUp).Row
'Sets the destination Row on the newSheet
nRow = 2
'oRow = Original Row.
For oRow = 2 To LastRow
'This is looking to Row# N:, Column A for the value = "step" contained in the text
'If the InStr (InString) function returns a value greater than 0 meaning "step" occurs
searchString = Sheets("laos").Cells(oRow, 1)
If InStr(searchString, "step") > 0 Then
'Assuming you have to loop through N points, Find the last column of the STEP row.
LastNCol = Sheets("laos").Cells(oRow, Columns.Count).End(xlToLeft).Column
'Label the new Row
Sheets(newSheet).Cells(nRow, 1) = Sheets("laos").Cells(oRow, 1)
'start loop with 2 for ColumnB
For n = 2 To LastNCol
'Copy the VALUE from the original sheet, and set the new sheet with it.
Value = Sheets("laos").Cells(oRow, n)
Sheets(newSheet).Cells(nRow, n) = Value
Next n
'Since we are done copying all the N Points to the New Row, we increment the nRow + 1
nRow = nRow + 1
'Must END IF
End If
Next oRow
End Sub
你打算用這一行完成什麼:'如果.Cells(n,1)=「step」Then' – 2014-10-28 16:16:16
你在尋找「step」嗎?或「步驟」?因爲空格將很重要 – peege 2014-10-28 21:19:35
我不明白N點記錄在哪裏?他們是否在「老撾」的專欄?你能把老撾頁面的截圖嗎?我會幫你的。我不明白你在哪裏得到了你的i Loop的價值9763。 – peege 2014-10-28 21:30:23