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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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