2017-01-24 5 views
0

は、私は良い動作するコードを持っているが、私はシートのセルB5のコピーデータ

値としていくつかの変更をしたい場合は、「2月」の範囲内のセルのいずれかが、どれも空白とSheets("Jan").Range("I5:AM81")ない場合If sheets("Feb").Range("I5:AK81)<>""(範囲内のセルのいずれかが "TRF"と等しくない場合は、範囲Sheets("master").Range("H7:Q200"),1,0)のシート "Jan"のセルセルB5をコピーして、シート "Feb"のセルB5に貼り付けます。

シートfebの範囲B5:B81の最後の空白欄に移動し、シートの列Oの日付(「マスター」)がある場合は範囲​​( "H7:q200")は現在の現在の月年に適切なセルbをコピーする電子レンジやシートの最後の空のセルに貼り付ける「2月」の範囲B5:B81ので、以下

には、これは巣に必要なあなたの第二の基準を許可し、そしてべきではないコード

Option Explicit 

Sub CopyRows() 

Dim Cl As Range 
Dim str As String 
Dim RowUpdCrnt As Long 

str = "WRK.*" 'string to look for 
Sheets("Feb").Range("B5:B81").Value = "" 

RowUpdCrnt = 5 

' In my test data, the "WRK."s are in column AN. This For-Each only selects column AN. 
' I assume all my "WRK."s are in a single column. Replace "B" by the appropriate 
' column letter for your data. 

With Sheets("Jan") 
' loop until last row with data in Column AN (and not the entire column) to save time 
    For Each Cl In .Range("AN1:AN" & .Cells(.Rows.Count, "AN").End(xlUp).Row) 
    If Cl.Value Like str And Sheets("Feb").Range(Cl.Address).Value <> "" Then 

    'if the cell contains the correct value copy it to next empty row on sheet 2 & delete the row 
     If Not IsError(Application.Vlookup(.Range("B" & Cl.Row).Value, Sheets("Master").Range("H7:H200"), 1, 0)) Then ' <-- verify the VLookup was successful 
     Sheets("Feb").Range("B" & RowUpdCrnt).Value = Application.Vlookup(.Range("B" & Cl.Row).Value, Sheets("Master").Range("H7:H200"), 1, 0) 
     RowUpdCrnt = RowUpdCrnt + 1 
     End If 
    End If 
    Next Cl 
End With 

Application.CutCopyMode = False 
End Sub 

答えて

0
If AND(criteria1,critieria2) then 

です別のifステートメント。

あなたが行っている方向に従うのが難しい種類なので、これが間違っている場合は修正してください。

.1)次に範囲シート( "マスター")のシート "Jan"でVLookupセルB5を範囲指定すると、範囲内の "so" "H7:Q200")、1,030

'You've got this. I would recommend index/match 
'using application and worksheet function commands. 

.2)コピーして、シート「Feb」のセルB5に貼り付けます。

With Sheets("Feb").Range("B5").PasteSpecial xlPasteValues 

0.3)は、範囲B5内の最後の空白の列に移動します。日付のいずれかのシート(「マスター」)の列Oであれば)シート2月のB81

Dim LR as Long 'LR is last row 
LR = Cells(Sheets("Feb").Rows.Count, 1).End(xlUp).Row 

0.4の範囲( "H7:Q200")は、現在の年の現在の月

'Assuming this sheet based... Assuming H is the date column 
If Sheets("master").Range("H7:H200").Value = "2" Then 

.4a)、その後範囲

'use index/match with output being Column(2)/B 
WorksheetFunction.Index(rangeB,WorksheetFunction.Match(reference,rangeH)).Copy 
に適切なセルBをコピーするに収まっ

.4bシートの最後の空のセルで)ペースト "2月" の範囲B5:B81

Sheets("Feb").Cells(LR+1,2).PasteSpecial xlPasteValues 

0.5)ので

にこれがうまくいけば、あなたにスタートを与えるだろう。できるだけ、手続き的に各ラインについて考えてください。

関連する問題