Save As New Excel Files Based on Column Value

JADownie

Active Member
Joined
Dec 11, 2007
Messages
395
I am trying to write a code that will split my current file by Column K and save as with new files

I keep getting an error at this step. Is it because my Instructions sheet is in the original file? Anyway to work around this now?

SvName = Sheets("Instructions").Range("C46")

wb.SaveAs strPath & "\" & strVal & "SvName.xlsx"


Sub CopyWorksheet()
Dim b As Integer, lastrow As Integer, lastcol As Integer
Dim wb As Workbook, wbCurr As Workbook
Dim strPath As String, strVal As String


strPath = Application.ActiveWorkbook.Path
Set wbCurr = ActiveWorkbook
lastrow = ActiveSheet.Range("K100000").End(xlUp).Row
lastcol = ActiveSheet.Range("xfd1").End(xlToLeft).Column
For K = 2 To lastrow
strVal = Range("K" & K)
Set wb = Workbooks.Add
ThisWorkbook.Activate
ActiveSheet.Range(Cells(1, 1), Cells(1, lastcol)).Copy
wb.Activate
wb.ActiveSheet.Range("a1").PasteSpecial (xlPasteValues)



Dim strName As String


SvName = Sheets("Instructions").Range("C46")

wb.SaveAs strPath & "\" & strVal & "SvName.xlsx"
wbCurr.Activate
Next K
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

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