VBA Excel Automatically Copy & Paste Specific cells based on IF statement - excel

The code I have placed below is a combination of what works and what i can't get to work.
The code that is not commented will copy cells to "sheet2" from "sheet1".
What I cannot get to work correctly is the code that I have disabled that would replace my Range Method of coping from "sheet1" to "sheet2".
Also my If Then Code is what will some up what I'm trying to accomplish. I'm trying to get the If statement to search all of column A and copy all Cars that are year 1991 to sheet2.
Mind my poor coding skills I'm Doing my best to show & explain so I can be helped.
Here is the Sheets 1 & 2
(hxxp://s15.postimg.org/orfw7tlaz/test.jpg)
OLD CODE
Sub Macro1()
Set a = Sheets("Sheet1")
Set b = Sheets("Sheet2")
Set c = Sheets("Sheet3")
Dim x
Dim z
Dim lastrow As Long, erow As Long
x = x + 1
z = 2
'lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
'lastrow = b.Cells(Rows.Count, 1).End(xlUp).Row
'For i = 2 To lastrow
lastrow = b.Range("A" & Rows.Count).End(xlUp).Row + x
'If a.Cells(i, 1) = “1991” Then
'a.Cells(i, 1).Copy
'erow = b.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'b.Paste Destination:=b.Range.Cells(erow, 4)
Range("A" & z).Copy Destination:=b.Range("D" & lastrow)
'a.Cells(i, 1).Copy
'b.Paste Destination:=b.Range.Cells(erow, 1)
Range("B" & z).Copy Destination:=b.Range("A" & lastrow)
'a.Cells(i, 1).Copy
'b.Paste Destination:=b.Range.Cells(erow, 3)
Range("C" & z).Copy Destination:=b.Range("C" & lastrow)
'a.Cells(i, 1).Copy
'b.Paste Destination:=b.Range(erow, 2)
Range("D" & z).Copy Destination:=b.Range("B" & lastrow)
'End If
'Next i
Application.CutCopyMode = False
Sheet2.Columns().AutoFit
'b.Range("A1").Select
End Sub
So I added some Lines and Began changing the cell locations to reflect the format I need and now when I run the macro it only copys the very last line from Sheet1 to sheet2. I believe it has to do with the order of the way these cells are.
b.Cells(erow, 1) = a.Cells(i, 1)
b.Cells(erow, 2) = a.Cells(i, 2)
b.Cells(erow, 3) = a.Cells(i, 3)
b.Cells(erow, 4) = a.Cells(i, 4)
Changing these back fixes it so it copys all the cells but its not what I'm trying to do.
The Code I'm Trying to run is Below
NEW CODE Working Thanks to EntryLevel!
Sub TakeTwo()
Dim a As Worksheet
Dim b As Worksheet
Dim c As Worksheet
Set a = ThisWorkbook.Sheets("Sheet1")
Set b = ThisWorkbook.Sheets("Sheet2")
Set c = ThisWorkbook.Sheets("Sheet3")
Dim i As Long
Dim lastrowsheet1 As Long
Dim erow As Long
lastrowsheet1 = a.Cells(Rows.Count, 1).End(xlUp).Row
erow = b.Cells(b.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
For i = 2 To lastrowsheet1
If a.Cells(i, 1).Value = "AEM" Then
b.Cells(erow, 31) = a.Cells(i, 1) '<------When I modify these
b.Cells(erow, 6) = a.Cells(i, 4) '<------The copied cells
b.Cells(erow, 28) = a.Cells(i, 5) '<------Don't show up
b.Cells(erow, 26) = a.Cells(i, 6) '<------In Sheet2
b.Cells(erow, 46) = a.Cells(i, 11) '<------Only the last
b.Cells(erow, 29) = a.Cells(i, 14) '<------Line found Is copied to sheet2
erow = erow + 1
End If
Next i
Application.CutCopyMode = False
b.Columns.AutoFit
'b.Range("A1").Select
End Sub
Now Using Same Working Code But Different function Not Working
Sub TakeThree()
Dim a As Worksheet
Dim b As Worksheet
Dim c As Worksheet
Set a = ThisWorkbook.Sheets("Sheet1")
Set b = ThisWorkbook.Sheets("Sheet2")
Set c = ThisWorkbook.Sheets("Sheet3")
Dim i As Long
Dim lastrowsheet1 As Long
Dim erow As Long
lastrowsheet1 = c.Cells(Rows.Count, 1).End(xlUp).Row
erow = b.Cells(b.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
For i = 2 To lastrowsheet1
If c.Cells(i, 1).Value = b.Cells(erow, 6).Value Then 'If serial number is found from sheet2 column 6 in sheet3 Column 1
b.Cells(erow, 8) = c.Cells(i, 2) 'Then copy description from sheet3 cell row to Sheet2 cell row
erow = erow + 1
End If
Next i
Application.CutCopyMode = False
b.Columns.AutoFit
c.Columns.AutoFit
'b.Range("A1").Select
End Sub
So I added another For Loop with Dim r and added another Line erow = erow + r & now the code copys the first 2 rows needed but does not continue iterating down the list. which is confusing me. here is the code below i have added.
Dim r As Long
Dim i As Long
Dim lastrowsheet1 As Long
Dim erow As Long
lastrowsheet1 = c.Cells(Rows.Count, 1).End(xlUp).Row
erow = b.Cells(b.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
For r = 1 To erow
For i = 2 To lastrowsheet1
If c.Cells(i, 1) = b.Cells(erow, 6) Then
b.Cells(erow, 8) = c.Cells(i, 2)
erow = erow + r
End If
Debug.Print i
Next i
Next r

Based on your statement that I'm trying to get the If statement to search all of column A and copy all Cars that are year 1991 to sheet2, it seems like Autofilter might be an easier solution than looping. You should be able to use something like this:
Sub TestyTestTest()
Dim lastrowsheet1 As Long
Dim lastrowsheet2 As Long
With ThisWorkbook.Sheets("Sheet1")
.AutoFilterMode = False
lastrowsheet1 = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range(.Cells(1, 1), .Cells(lastrowsheet1, 4)).AutoFilter Field:=1, Criteria1:="1991"
.Range(.Cells(2, 1), .Cells(lastrowsheet1, 4)).SpecialCells(xlCellTypeVisible).Copy
.AutoFilterMode = False
End With
With ThisWorkbook.Sheets("Sheet2")
.AutoFilterMode = False
lastrowsheet2 = .Cells(.Rows.Count, 1).End(xlUp).Row
.Cells(lastrowsheet2 + 1, 1).PasteSpecial Paste:=xlPasteValues
.AutoFilterMode = False
End With
Application.CutCopyMode = False
End Sub
EDIT:
Trying to stick close to your original code, would something like this be more like what you are looking for?
Sub TakeTwo()
Dim a As Worksheet
Dim b As Worksheet
Dim c As Worksheet
Set a = ThisWorkbook.Sheets("Sheet1")
Set b = ThisWorkbook.Sheets("Sheet2")
Set c = ThisWorkbook.Sheets("Sheet3")
Dim i As Long
Dim lastrowsheet1 As Long
Dim erow As Long
lastrowsheet1 = a.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrowsheet1
If a.Cells(i, 1).Value = 1991 Then
erow = b.Cells(b.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
b.Cells(erow, 1) = a.Cells(i, 1)
b.Cells(erow, 2) = a.Cells(i, 2)
b.Cells(erow, 3) = a.Cells(i, 3)
b.Cells(erow, 4) = a.Cells(i, 4)
End If
Next i
Application.CutCopyMode = False
b.Columns.AutoFit
End Sub
SECOND EDIT - OP's NEW PROBLEM:
It looks like your data is just pasting over itself because erow is defined as the row after the last row in column 1 that is not empty, but you are not actually putting any data into that column, so erow isn't moving down to the next line.
Basically, change the column number in this line:
erow = b.Cells(b.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
The 1 in b.Cells(b.Rows.Count, 1) should be changed to a column number that you paste data into every time. Alternatively, you could use erow as a counter and increment it manually each time through the loop. In that case move the existing line that defines erow up underneath the line that defines lastrowsheet1 and then put erow = erow + 1 inside the loop after all the pasting has taken place but before End if. If you put it after End If, you'll end up with a bunch of blank lines between your data.

Related

Macro copies certains column from one sheet to other. Fine can't get it to paste from row 4 on sheet 2 instead of row 2

Macro copies certain columns from one sheet to other. I can't get it to paste from row 4 on sheet 2 instead of row 2.
Sub CopyPaste()
Dim lastrow As Integer, erow As Long, sheet1 As Worksheet, sheet2 As Worksheet
Set sheet1 = Worksheets("Sheet1")
Set sheet2 = Worksheets("Sheet2")
lastrow = sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
erow = sheet2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
sheet2.Cells(erow, 2) = sheet1.Cells(i, 3)
sheet2.Cells(erow, 3) = sheet1.Cells(i, 4)
sheet2.Cells(erow, 4) = sheet1.Cells(i, 9)
Next i
End Sub
skip the loop and assign the whole range as one:
Sub CopyPaste()
Dim sheet1 As Worksheet
Set sheet1 = Worksheets("Sheet1")
Dim sheet2 As Worksheet
Set sheet2 = Worksheets("Sheet2")
Dim lastrow As Long
lastrow = sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Dim erow As Long
erow = sheet2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
sheet2.Cells(erow, 2).Resize(lastrow - 1).Value = sheet1.Cells(2, 3).Resize(lastrow - 1).Value
sheet2.Cells(erow, 3).Resize(lastrow - 1).Value = sheet1.Cells(2, 4).Resize(lastrow - 1).Value
sheet2.Cells(erow, 4).Resize(lastrow - 1).Value = sheet1.Cells(2, 9).Resize(lastrow - 1).Value
End Sub

Multiple If Functions

I need some help for my code. I want to copy client's name on column C based on these 2 conditions if:
Macro find value = "ongoing" on Column G
Macro find value = "Istry" on column D
In other words if macro find "ongoing" and "istry" at same row, it will copy automatically the client's name associated with these 2 values asked on another sheet.
I wrote a code but when I tried to run it, I didn't get any result on my sheet.
Sub Ss()
Dim finalrow As Long, i As Long, rowpt As Long, colpt As Long
finalrow = ShSReturn.Range("D" & "G" & Rows.Count).End(xlUp).Row
rowpt = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row
colpt = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row
Call Entry_Point
For i = 7 To finalrow
If ShSReturn.Cells(i, 4).Value = "Istry" & ShSReturn.Cells(i, 7).Value = "Ongoing" Then
ShSReturn.Cells(i, 3).Copy
ShPPT.Cells(rowpt + 6, 12).PasteSpecial xlPasteValues
rowpt = rowpt + 1
colpt = colpt + 1
End If
Next i
End Sub
Making some assumptions here about your intent for this code here is a quick rewrite:
Sub Ss()
Dim finalrow As Long, i As Long, rowpt As Long, colpt As Long
'Determine how many rows we need to loop:
finalDRow = ShSReturn.Range("D" & Rows.Count).End(xlUp).Row
finalGRow = ShSReturn.RAnge("G" & Rows.Count).End(xlUp).Row
'Loop only through rows were both G and D have records
If finalDRow < finalGRow Then finalrow = finalDRow Else finalRow = finalGRow
'I don't know what these two are doing, but they will return the same exact number (the last row populated in column A of whatever worksheet object is in ShPPT
rowpt = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row
colpt = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row
Call Entry_Point
'Loop through rows 7 to whatever finalRow shakes out to be above
For i = 7 To finalrow
'If column D is "Istry" AND column G is "Ongoing" Then execute this code.
If ShSReturn.Cells(i, 4).Value = "Istry" AND ShSReturn.Cells(i, 7).Value = "Ongoing" Then
ShSReturn.Cells(i, 3).Copy
ShPPT.Cells(rowpt + 6, 12).PasteSpecial xlPasteValues
rowpt = rowpt + 1
colpt = colpt + 1
End If
Next i
End Sub
You can use a Filter.
Be sure to set the appropriate worksheet references.
As written, the code copies the entire row, but you can easily modify it if you only want a few fields to be copied over.
Option Explicit
Option Compare Text
Sub filterName()
Const strG = "ongoing"
Const strD = "lstry"
Dim rCopyTo As Range
Dim rData As Range
Dim lastRow As Long, LastCol As Long
With Worksheets("Sheet6")
lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
Set rData = .Range(.Cells(1, 1), .Cells(lastRow, LastCol))
End With
Set rCopyTo = Worksheets("sheet7").Cells(1, 1)
Application.ScreenUpdating = False
rData.AutoFilter field:=4, Criteria1:=strD, visibledropdown:=False
rData.AutoFilter field:=7, Criteria1:=strG, visibledropdown:=False
rCopyTo.Cells.Clear
rData.SpecialCells(xlCellTypeVisible).Copy rCopyTo
rData.Worksheet.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub

Extract rows from multiple sheets into one and exclude any row with #N/A

I have one sheet of data where I need to extract the values from multiple columns and assign them a value. Column A is a string where column B is the assigned value. Columns C and D are vlookups based on column A and they will need the assigned value from column B as well. Please see the screenshots. I would need to compile a list on a separate sheet. Ideally column A would have the data from columns A, C and D from the other sheet and column B would have the assigned values. Only caveat is I need to exclude any row that has #N/A
Any macro that may work would be very helpful!
Code I was using
Sub Life_Saver_Button()
Dim lastrow As Long, erow As Long
Set S1 = Worksheets("Sheet1")
Set S2 = Worksheets("Sheet2")
lastrow = ThisWorkbook.Sheets("S1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
S1.Cells(i, 1).Copy
erow = ThisWorkbook.Sheets("S2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ThisWorkbook.Sheets("S1").Paste Destination:=ThisWorkbook.Sheets("S2").Cells(erow, 1)
ThisWorkbook.Sheets("S1").Cells(i, 2).Copy
ThisWorkbook.Sheets("S1").Paste Destination:=ThisWorkbook.Sheets("S2").Cells(erow, 2)
ThisWorkbook.Sheets("S1").Cells(i, 3).Copy
ThisWorkbook.Sheets("S1").Paste Destination:=ThisWorkbook.Sheets("S2").Cells(erow, 1)
ThisWorkbook.Sheets("S1").Cells(i, 4).Copy
ThisWorkbook.Sheets("S1").Paste Destination:=ThisWorkbook.Sheets("S2").Cells(erow, 2)
ThisWorkbook.Sheets("S1").Cells(i, 5).Copy
ThisWorkbook.Sheets("S1").Paste Destination:=ThisWorkbook.Sheets("S2").Cells(erow, 1)
ThisWorkbook.Sheets("S1").Cells(i, 5).Copy
ThisWorkbook.Sheets("S1").Paste Destination:=ThisWorkbook.Sheets("S2").Cells(erow, 2)
Next i
Application.CutCopyMode = False
ThisWorkbook.Sheets("S2").Columns().AutoFit
Range("A1").Select
End Sub
Try:
Option Explicit
Sub test1()
Dim LastrowA As Long, Lastrow As Long, cell As Range, Code As Long
Dim Desc As String
With ThisWorkbook.Worksheets("Sheet1")
LastrowA = .Cells(.Rows.Count, "A").End(xlUp).Row
For Each cell In .Range("A1:D" & LastrowA)
If Not IsError(cell.Value) = True And Not IsNumeric(cell.Value) = True Then
Desc = cell.Value
Code = .Range("B" & cell.Row).Value
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
If LastrowA = Lastrow Then
.Range("A" & Lastrow + 2).Value = Desc
.Range("B" & Lastrow + 2).Value = Code
Else
.Range("A" & Lastrow + 1).Value = Desc
.Range("B" & Lastrow + 1).Value = Code
End If
End If
Next
End With
End Sub
Results:

Cut and paste the value of cell to another cell in vba

I need to transfer or move the value of Column F until last cell with value to Column D if Column C is eq to 'RRR'. I can't highlight or select the range starting from the Location of 'RRR' to the last cell with value 'SSS'. Instead, it select range from C4:C9 which is wrong.
Dim ws As Worksheet, lRow As Long
Set ws = ThisWorkbook.ActiveSheet
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
Dim lCol As Long
With ws
For x = 1 To lRow
If .Cells(x, 3).Value = "RRR" Then
lCol = Cells(x, Columns.Count).End(xlToLeft).Column
Range("C" & x & ":C" & lCol).Select
End If
Next x
End With
Example:
Expected:
Can anyone tell me the problem in my code.
You are very near, only the select range that should be modified.
So you can build your range:
Range(A1:D1) -> Range(Cells(A1), Cells(D1)) ->
Range(Cells(row number, column number), Cells(row number, column number)) ->
Range(Cells(1, 1), Cells(1, 4))
This should do the trick:
Dim ws As Worksheet, lRow As Long
Dim x As Long
Set ws = ThisWorkbook.ActiveSheet
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
Dim lCol As Long
With ws
For x = 1 To lRow
If .Cells(x, 3).Value = "RRR" Then
lCol = Cells(x, Columns.Count).End(xlToLeft).Column 'Find the last column number
Range(Cells(x, 6), Cells(x, lCol)).Cut Cells(x, 4) 'Cut from row x and Column F (Column F = 6) to row x and column "lCol". Then paste the range into row x and column 4.
End If
Next x
End With
End Sub
An alternative method would be to delete the cells in columns D and E
Dim ws As Worksheet, lRow As Long
Dim x As Long
Set ws = ThisWorkbook.ActiveSheet
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
Dim lCol As Long
With ws
For x = 1 To lRow
If .Cells(x, 3).Value = "RRR" Then .Range("C" & x & ":D" & x).Delete Shift:=xlToLeft
End If
Next x
End With
End Sub

Copy rows from one table to another without creating duplicates

I have an Excel workbook that has a master sheet that keeps track of items and their current location, and another sheet that keeps track of past locations or where an item has been. Currently when a record is changed in the master sheet, the row is manually copied and pasted into the 2nd sheet. I would like to create a macro that would find items in the master sheet that are not in the 2nd sheet and copy them to the 2nd sheet when records change.
Below is a sample macro I found and modified that is close, but it copies and pastes all rows instead of the new or different ones. The rows would only need to be compared on columns A, B, and D.
Public Sub Sample()
Dim shM As Worksheet, sh2 As Worksheet
Dim shMData As Variant
Dim sh2DataA As Variant
Dim sh2Data As Variant
Dim iM As Long, os2 As Long, i2 As Variant
Dim DoSearch As Boolean
Set shM = Sheets(1)
Set sh2 = Sheets(2)
With shM
shMData = .Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 4)
End With
DoSearch = False
For iM = 2 To UBound(shMData, 1)
With sh2
sh2DataA = .Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 1)
sh2Data = .Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 4)
End With
os2 = 0
Do
If UBound(shMData, 1) > 1 Then
i2 = Application.Match(shMData(iM, 1), sh2DataA, 0)
Else
If shMData(iM, 1) = sh2DataA Then
i2 = 1
Else
i2 = CVErr(xlErrNA)
End If
End If
If Not IsError(i2) Then
If (shMData(iM, 2) = sh2Data(i2, 2)) And (shMData(iM, 4) = sh2Data(i2, 4)) Then
MsgBox "Match found Master = " & iM & ", sheet2 = " & i2 + os2
Else
shM.Activate
shM.Range(Cells(iM, 1), Cells(iM, 7)).Select
Selection.Copy
sh2.Select
FinalRow = Range("A65536").End(xlUp).Row
NextRow = Range("A65536").End(xlUp).Row + 1
Range("A" & NextRow).Select
ActiveSheet.Paste
End If
os2 = os2 + i2
If os2 < UBound(sh2Data, 1) Then
With sh2
sh2DataA = .Range(.Cells(i2 + os2, 1), .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 1)
sh2Data = .Range(.Cells(i2 + os2, 1), .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 4)
End With
DoSearch = True
Else
DoSearch = False
End If
Else
shM.Activate
shM.Range(Cells(iM, 1), Cells(iM, 7)).Select
Selection.Copy
sh2.Select
FinalRow = Range("A65536").End(xlUp).Row
NextRow = Range("A65536").End(xlUp).Row + 1
Range("A" & NextRow).Select
ActiveSheet.Paste
DoSearch = False
End If
Loop Until Not DoSearch
Next
End Sub
The message box was added only to verify that the code was working - it is not a necessary component. Thanks again for any advice you can give.
Assuming you never get two rows of the exact same thing in your master list, you can just use the built-in Excel feature Remove Duplicates (on the Data tab in 2010 at least). If you have x duplicate rows, all the same, x-1 of them are deleted. So, you could just copy the entire other table, paste it below the master list, and then run remove duplicates on the master list. All you need to know is the VBA for removing duplicates.
ActiveSheet.Range("$A$40:$D$43").RemoveDuplicates Columns:=Array(1, 3, 4), Header:=xlNo
Adjust as necessary
Thank you all for your help I found a solution however it does not work in Excel 2003. If anyone knows off the top of their head why that would be great else I think I figure it out. Here is the code.
[HTML]Public Sub NewEntWhole()
Dim loM As ListObject, lo2 As ListObject
Dim TblMData As Variant
Dim iM As Long
Dim dDate As Date
Dim strDate As String
Dim lDate As Long
Dim rng As Range
Dim ct As Variant
Dim shM As Worksheet
Dim sh2 As Worksheet
Dim hdM As Integer
hdM = 0 'rows above table M
Set shM = Sheets(1)
Set sh2 = Sheets(2)
Set loM = Sheets(1).ListObjects(1)
Set lo2 = Sheets(2).ListObjects(1)
With loM
TblMData = .DataBodyRange
End With
For iM = 2 To UBound(TblMData, 1) + 1
sh2.Activate
With lo2
.Range.AutoFilter Field:=1, Criteria1:=loM.Range(iM, 1).Value
.Range.AutoFilter Field:=2, Criteria1:=loM.Range(iM, 2).Value
If IsDate(loM.Range(iM, 4)) Then
sDate = loM.Range(iM, 4)
dDate = DateSerial(Year(sDate), Month(sDate), Day(sDate))
lDate = dDate
.Range.AutoFilter Field:=4, Criteria1:=">=" & lDate, Operator:=xlAnd, Criteria2:="<" & lDate + 1
Else
.Range.AutoFilter Field:=4, Criteria1:=loM.Range(iM, 4).Value
End If
End With
Set rng = lo2.AutoFilter.Range
ct = rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
If ct = 0 And loM.Range(iM, 1).Value > 0 Then
shM.Activate
shM.Range(Cells((iM + hdM), 1), Cells((iM + hdM), 7)).Copy
sh2.Activate
FinalRow = Range("B65536").End(xlUp).Row
NextRow = Range("B65536").End(xlUp).Row + 1
Range("A" & NextRow).Select
ActiveSheet.Paste
End If
With lo2
.Range.AutoFilter Field:=1
.Range.AutoFilter Field:=2
.Range.AutoFilter Field:=4
End With
Next
shM.Activate
End Sub[/HTML]

Resources