Create/Save New File per change in column

nickwilshaw

New Member
Joined
Apr 18, 2011
Messages
13
Hi Guys,

I have a macro that allows me to create a file where there is a change in the name of the column and save it with that new name:

Sub FindNextCustomer()
Workbooks("Book1.xlsm").Activate
Sheets("Customers").Activate
Range("A2").Select
b = Range("A2").Value
Do While ActiveCell.Value = b
ActiveCell.Offset(1, 0).Select
Loop
a = ActiveCell.Value
Workbooks.Add.SaveAs Filename:="H:\Accounts\Nick\Loan Guarantees\" & a & ".xls"
End Sub

However, I cannot get this to loop back on itself to go and look for subsequent instances and repeat

I have tried putting If/Else statements within the loop such as

IF ActiveCell.Offset(1, 0).Value = ActiveCell.Value then ActiveCell.Offset(1, 0).Select
Else a = ActiveCell.Value
Workbooks.Add.SaveAs Filename:="H:\Accounts\Nick\Loan Guarantees\" & a & ".xls

But I get the Else without If Error.

Again, any help would be greatly appreciated.

Also, are there any easy-to-understand references on Loops, ranges, Dim (whatever they are!) - I am only an accounts bod and don't have any IT quals so pls be sympathetic!

Ta,
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,223,786
Messages
6,174,547
Members
452,571
Latest member
MarExcelTips

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