How to break master file into multiple wb and rename them based on file name coulmn

Learning1

New Member
Joined
Aug 13, 2018
Messages
15
I have a quick question, I have 50K lines in master files and trying to break 6000 line per file. However, I want to save the file name based on file name column.



For example: lets say I have 10K lines for company name “XYZ” but I want break the file into two files , first file with xyz___00001 and with 6000k lines and second file XYZ_00002 but please notice the column file name is blank after the first till next company name. Other file name should be based on the new customer name “DCB_00001” and so on. Is this possible?



My current VBA code breaks up the files into 6kLines and rename it test_00001 and so on. Any help would be much appreciated. Thanks in advance for your’s response! Below is my VBA code without showing you the declared variables.



'Number of rows to create a new workbook

limit = 6



Set sht = ActiveSheet

Set head = sht.Rows(1)

Set cll = sht.Cells(2, 1)

Do Until cll.Value = ""

i = i + 1

Set rng = cll.Resize(limit, Cells(cll.Row, Columns.Count).End(xlToLeft).Column)





Set wrk = Application.Workbooks.Add

head.Copy wrk.Worksheets(1).Cells(1, 1)

rng.Copy wrk.Worksheets(1).Cells(2, 1)

wrk.SaveAs ThisWorkbook.Path & Application.PathSeparator & prefix & "_" & Format(i, "0000") 'Trying to make filename zero padded

wrk.Close

Set cll = cll.Offset(limit)

Loop



Application.ScreenUpdating = True



End Sub



1622048168236.png
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,800
Messages
6,126,980
Members
449,351
Latest member
Sylvine

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top