Path not found, but the folders do exist
[code] Sub toPDF() ' This will copy a specified range('s) from ws1 & ws2 to ws3. ' Now you can...
I believe the problem is that you are not getting the sFileName from the original workbook. So I have added ActiveWorkbook.Save...
Hello Ready2go This may only answer some of your question. The macro below will create a PDF file of Sheet2....
Dear Hyside2, I really appreciate your cooperation and helpful answer. Thanks so much.
Try this instead =IFERROR(LEFT(B1,FIND(" ",B1)-1),B1) [img alt_text='' description='']http://vbaf1.com/q/wp-content/uploads/2018/08/givenname.png[/img]
I am not sure if this is what you are looking for but test it out anyway. [img alt_text='' description='']http://vbaf1.com/q/wp-content/uploads/2018/08/1-2.png[/img]...
Oh! Please try this. You will need to change "Book1" on the line that reads (oFilename="Book1") to the name of...
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).