2014-10-28 4 views
0

글쎄, 나는 VBA에서 초보자이기 때문에 도움이 필요하다. 그래서 저는 많은 데이터를 가진 실험 파일을 가지고 있습니다. 기본적으로 21 가지 측정 단계가 있으며 N 단계마다 N 포인트가 기록됩니다. 모든 단계는 하나의 워크 시트에 있으며 "단계"라는 단어로 그 단어를 발견 할 수 있습니다. N 포인트를 복사하여 다른 시트로 보내려는 각 단계마다 매크로를 작성했지만 새 시트를 만드는 것 외에는 아무 것도 발생하지 않습니다.VBA, 다른 워크 시트에 행을 많이 복사하여 붙여 넣기

Sub mymacro() 
 

 
Worksheets("laos").Activate 
 
Dim n As Long 
 
Dim i As Byte 
 
Dim LastRow As Long 
 
Dim WS As Worksheet 
 
Set WS = Sheets.Add 
 

 
With Worksheets("laos") 
 
     LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 
 
End With 
 

 
For n = 1 To LastRow 
 
    With Worksheets("laos") 
 
      If .Cells(n, 1) = " step " Then 
 
       For i = 1 To 9763 'N points recorded 
 
       .Rows(i).Copy Destination:=WS.Range("A" & i) 
 
       Next 
 
      End If 
 
    End With 
 
Next 
 

 
End Sub

+0

이 줄로 무엇을하고자하셨습니까?'.Cells (n, 1) = "step"Then' –

+0

"step"을 찾으십니까? 또는 "단계"? 공백이 중요하기 때문에 – peege

+0

N 포인트가 기록 된 곳을 모르겠습니다. 그들은 "라오스"란에 있습니까? 라오스 페이지의 스크린 샷을 넣을 수 있습니까? 도움이 될거야. 나는 당신이 당신의 i Loop에 대한 가치 9763을 어디서 얻었는지 이해하지 못합니다. – peege

답변

0

이 당신은 내가 아마하지 않았다 원래 게시물을 이해하면 어떻게 찾고 어떻게해야 : 아래 내 코드에 모습을 가질 수 있습니다. 시트 레이아웃에 대한 자세한 내용은 도움이 될 것입니다. 이 개념은 아마도 당신이 찾고있는 것을 가르치기에 충분할 것입니다. 제공된 스크린 샷을보고 레이아웃을 이해하십시오.

이 예에서는 이미 대상 시트를 만들었습니다. 이 예제의 "당신이 그 시트 NAMED 뭐든"변수 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 

laos Sheet Target Sheet

0

미안 해요. 저는 정확하지 않았습니다. 워크 시트의 스크린 샷을 게시할만한 충분한 평판을 얻지 못했습니다. 그래서 N 포인트가 기록 된 Sine Strain 측정 값을 얻었습니다 (코드 N = 9763이지만 변경할 수 있음). 22 사인 변형 (또는 단계)입니다. 모든 것은 같은 워크 시트에 있습니다. 결국 시트 당 한 개의 사인 변형이 필요합니다 (다른 시트의 이름은 신경 쓰지 않습니다).

당신이 유용 할 것입니다.

나는 코드로 뭔가를하려고 노력할 것이다.

관련 문제