I have a code which works good but i want some modifications as
Value of cell B5 in Sheet "feb" If sheets("Feb").Range("I5:AK81)<>""
(if any of the cell in range is none-blank and Sheets("Jan").Range("I5:AM81")
is not equal to "TRF." means if any of the the cell in range is not equal to "TRF." then VLookup
cell B5 in sheet "Jan" in range Sheets("master").Range("H7:Q200"),1,0)
and copy it and paste in cell B5 of sheet "Feb".
and go to last blank column in range B5:B81 of sheet feb and if any of date in column O of Sheets("master").Range("H7:q200") falls only within current month of current year then copy appropriate cell b in the range and paste in last empty cell of sheet "Feb" range B5:B81 and so on
Below is code
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
This should allow you a second criteria, and not need to nest another if statement.
Kind of hard to follow the direction you're going, so correct me if this is wrong. Not quite getting the "so on" part of this, but we can try to break down some of this:
.1) then VLookup cell B5 in sheet "Jan" in range Sheets("master").Range("H7:Q200"),1,0)
.2) copy it and paste in cell B5 of sheet "Feb".
.3) go to last blank column in range B5:B81 of sheet feb
.4) if any of date in column O of Sheets("master").Range("H7:q200") falls only within current month of current year
.4a) then copy appropriate cell b in the range
.4b) paste in last empty cell of sheet "Feb" range B5:B81
.5) so on
This will hopefully give a start to you. Just think about each line procedurally, if you can.