HI, Here is the required macro to search a field and if value found copy the whole row into another...
I found a solution like this :Records in between two specific dates easily can be filtered using drop-down lists ....
I found a solution as follows: Watch the video to see how it's done and download example file : https://youtu.be/SZduAoOtiS0
I have sorted the above problem. Code is given below... [code] Sub seperate() Call CleanSheets MsgBox "1 of 10 Cleaning...
Hi, Here is the VBA code to Split the Workbook into different Files by Each Sheet in the file and...
Hi, You can loop through the Sheet using Workbook Sheets Collection. See the Updated Code below: [code] Sub sbDeleteRows() 'Array...
Hi, We can follo several methods to fill the unique values from the worksheet to ListBox. Here is my preferred...
I have a macro code that opens up excel files and adds them up to an existing workbook (that is already open) with already 19 worksheets (worksheet names as follows: “result”, “1”, “2”, “3”,.. until “18”).
Now after adding the new worksheets (18 total as well with varying sheet names, and is always changing), I will filter the column AG (criteria =1) fo each newly added worksheet and copy them accordingly to existing worksheets “1” until “18”. However, this is how I want it to go: The filtered contents of 1st newly added worksheet gets copied to sheet “1”, the 2nd newly added worksheets filtered contents get copied to sheet “2”, and so on until the 18th newly added worksheet filtered contents gets copied onto sheet “18”.
Appreciate if you could help me write a code based on this.thanks a lot!
Assuming your order of worksheets start from left: “result”, “1”, “2”, “3”,.. until “18”, New 1, New 2,…, New 18. This macro do not consider the worksheets and it depends on the order. i.e; Worksheet #2 is “1” and Worksheet#19 is “18”, Worksheet#20 is New 1 , Worksheet#21 is New 2, so on.
So, Worksheet#20 data will be updated into Worksheet#2. Here is the macro to filter the new worksheet and copy & paste the filtered data into the respective target Sheet:
Dim i, NumSheets As Integer
Dim lastRow As Long
NumSheets = 18
For i = 1 To NumSheets
'Filter the new source sheet and copy the content
Sheets(NumSheets + 1 + i).Activate
'Find the last free row in destination sheet and paste
Sheets(i + 1).Activate
lastRow = ActiveSheet.Cells.SpecialCells(xlLastCell).Row
Do While Application.CountA(ActiveSheet.Rows(lastRow)) = 0 And lastRow <> 1
lastRow = lastRow - 1
Range("A" & lastRow + 1).Select
FieldToFilter = 33 ' = Column AG
ActiveSheet.Cells.AutoFilter Field:=FieldToFilter, Criteria1:="1"
Thanks, PNRao! The code works perfectly. I just had to move sheets according to your code, since originally when the new sheets are added, they are placed into worksheets#2-#20. I don’t know how to automatically placed the new worksheets into the worksheet#20 and so on..
You are most welcome! You can use sheets.count and add the new sheets after #Sheets. So that your new sheets will be always adding at end.
You can share the existing code to import, I will help in modifying it.
Hi Mr. PNRao, thanks for your help. WIth your comment, i managed to figure out how to do it. I basically changed the index number reference for the sheet from Sheets(1) to Sheet(19). Here is the final working code.
Path = "C:AOI database"
Filename = Dir(Path & "*.CSV")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=False
For Each Sheet In ActiveWorkbook.Sheets
Filename = Dir()
Thanks for your feedback. I am glad to know that you found our codes helpful.
Please share using the share button above.
If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.
Found the answer useful and wants to credit the user, then vote the answer (vote up).