Aug 11 2018 04:12 PM
Hi
This is a complicated task that requires a VBA expert. I have attached a file for you to review. What I would like is a VBA code to be able to take the data and split it into separate worksheet per dept. So I want to filter out one dept at a time on one worksheet. Importantly I want the subtotal at the bottom to remain. So the subtotal would show the filtered total per dept.
Also is it possible to rename the new worksheets with the Dept name as well?
Please let me know if you can assist with this as it will save me so much time.
Thank you in advance.
Zia
Aug 11 2018 05:19 PM
You may refer to the attached file. (Just wonder that xlsm-file are allowed to upload)
The program will determine whether a department is "new" and then create the corresponding worksheets. I myself prefer to create a blank template and then copy the template in case it is a "new department" so that you need not to concern the formatting.
For each output, the cell J4 is counting the row number in the sheet. Since I am not sure that your real file consists of other worksheets or not, I cannot clear that contents. You may delete it manually. This procedure can be solved if you already have the list of departments. In this case, you can create worksheets (or copy from template) according to the list and then at end delete J4 for each worksheet corresponds to the department.
Hope that it is helpful to you.
Aug 12 2018 12:02 AM
Hi Man
Thank you for this I am very grateful. It works brilliantly. I have a few questions regarding this code. The data file was a test file.
Can I ask when I am working with these sort of files the range of the data will be different ie the data might start in cell A1 or P1. The number of columns used would be different ie the data may go from column K to column U. The number of rows will also vary depending on the data. The subtotal as a result would be in different cells each time I run the report.
What part of this code needs to change in order to reflect the above variations.
Look forward to your reply.
Zia
Aug 12 2018 01:25 AM
You have to understand the range and cells.
Range("J4") means the cell J4
Range("E" & r_CS &":H" & r_CS) represents the cells from column E to column H in the r_CS-th row.
On the other hand, we may consider cells as well.
Cells(1,2) means the cell in 1st row and 2nd column, i.e. the cell B1
You may also represent it as Cells(1,"B") in case you don't want to count the order of letters.
Aug 12 2018 02:28 AM
Hi Man
Thank you for the reply. I have tried to follow your instructions but I can't get it to work. I have changed the location of the data. Can you have a look and tell me what need to change in order to get this to work again. Please could you add additional comments to the VBA code so I can see what you are changing in order to make the VBA code work.
Thank you in advance.
Zia
Aug 12 2018 07:13 AM
SolutionI do not modified the program but just insert more comment for the changes. Hope you can learn it.
Aug 12 2018 01:53 PM
Man
Thank you for your assistance today. I appreciate it.
How did you learn so much about VBA?
Zia
Aug 12 2018 04:53 PM
I have some basic knowledge in computer programming in learning Pascal when I were a student. So that I have concepts on for-loop / while-loop.
For the VBA syntax, I just search the internet for information and then learn it little by little. Another way is to record the macro so that I know some keyword in some operation and then, again, search the internet.
Actually, there is a lot of thing in VBA that I did not know.
Aug 20 2018 12:11 AM
Aug 20 2018 12:24 AM
Aug 20 2018 12:32 AM
Aug 20 2018 12:42 AM
I'm trying to remove it from this section
I'm sending a photo
Aug 12 2018 07:13 AM
SolutionI do not modified the program but just insert more comment for the changes. Hope you can learn it.