2017-03-21 9 views
0

以下のコードがあります。ループは、ワークシート1の1行からすべてのデータを「コピー」し、ワークシート2の「ペースト」します。私が持っている問題は、私は行がworksheet2に貼り付けますが、列Bとではない列Aから開始する必要があるということである問題が、この行に起こるVBAの行全体を選択します。

Do While rowCounter < 2200 
    If Cells(rowCounter, colCounter).Value <> "AP Statistics Summary" Then 
     ThisWorkbook.Sheets("Throughput Per AP").Rows(throughputAP).Offset(1, 0).Value = ThisWorkbook.ActiveSheet.Rows(rowCounter).Value 
     throughputAP = throughputAP + 1 
    End If 
    rowCounter = rowCounter + 1 
Loop 

ThisWorkbook.Sheets("worksheet2").Rows(throughputAP).Offset(1, 0).Value = ThisWorkbook.ActiveSheet.Rows(rowCounter).Value 

のでコードOKを実行しますが、データはワークシート2の列Aからコピーされ、列Bから開始する必要があります

助けてください!

+1

それが動作するかどうか、私はSHUREないんだけど、あなたは試してみました:。 ThisWorkbook.Sheets(「worksheet2」)を行(throughputAP).Offset( 1、0).Value = ThisWorkbook.ActiveSheet.Rows(rowCounter)**。オフセット(1,0)** .Value – tretom

+0

@tretomこんにちは、いいえ、それはしませんでした仕事.....同じ結果 –

答えて

2

は、列A(すなわちコピーBにあることをコピーします:XFC):

'Using a With simply to shorten the code 
With ThisWorkbook.ActiveSheet.Rows(rowCounter) 
    ThisWorkbook.Sheets("worksheet2").Rows(throughputAP + 1).Resize(1, .Columns.Count - 1).Value = _ 
        .Resize(1, .Columns.Count - 1).Offset(0, 1).Value 
End With 

それとも、あなたがコピーしようとしている場合:BにXFCを:XFDをあなたは

'Using a With simply to shorten the code 
With ThisWorkbook.ActiveSheet.Rows(rowCounter) 
    ThisWorkbook.Sheets("worksheet2").Rows(throughputAP + 1).Resize(1, .Columns.Count - 1).Offset(0, 1).Value = _ 
        .Resize(1, .Columns.Count - 1).Value 
End With 
を行うことができます

それとも、あなたが列文字をハードコードに満足している場合、あなたは

ThisWorkbook.Sheets("worksheet2").Rows(throughputAP + 1).Range("A1:XFC1").Value = _ 
        ThisWorkbook.ActiveSheet.Rows(rowCounter).Range("B1:XFD1").Value 

またはスイッチングに使用することができますが、反対方向に

に行きたい場合は、「A1:XFC1」と「XFD1 B1を」 (コードのこれらのビットは、あなたが問題を抱えている行を置き換える。)

0

以下のコードを試してください。EntireRowがコピーされ、PasteSpecial xlValuesを使用して値のみを貼り付けます。

Do While rowCounter < 2200 
    If Cells(rowCounter, colCounter).Value <> "AP Statistics Summary" Then 
     ThisWorkbook.ActiveSheet.Rows(rowCounter).Copy 
     ThisWorkbook.Sheets("Throughput Per AP").Rows(throughputAP).Offset(1, 0).PasteSpecial xlValues 
     throughputAP = throughputAP + 1 
    End If 
    rowCounter = rowCounter + 1 
Loop 

しかし、あなたのケースでは、私はFor rowCounterであなたのDo Whileを置き換えます。

また、Worksheetsであり、ActiveSheetではなく、完全修飾名を使用してください。 XFD:あなたは、その後、あまり広いフル行よりも1列であることをソース行のサイズを変更することができるはずですあなたのコードの

バージョン2

For rowCounter = 2 To 2200 ' <-- start from 2 (or your start row) 
    With Worksheets("YourSheetName") ' <-- put here you sheet's name instead of ActiveSheet 
     If .Cells(rowCounter, colCounter).Value <> "AP Statistics Summary" Then 
      .Rows(rowCounter).Copy 
      ThisWorkbook.Sheets("Throughput Per AP").Rows(throughputAP).Offset(1, 0).PasteSpecial xlValues 
      throughputAP = throughputAP + 1 
     End If 
    End With 
Next rowCounter 
関連する問題