Here is another solution in VBA
Option Explicit
Sub CopyToNew()
Dim wb As Workbook
Set wb = ThisWorkbook
Dim lr As Long
lr = Range("C" & Rows.Count).End(xlUp).Row
Dim i As Long
Application.ScreenUpdating = False
For i = 2 To lr
If Range("B" & i) = "" Then Range("B" & i) = Range("B" & i - 1)
Next i
Dim myPath As String
myPath = "C:/Users/Alan Sidman/Desktop/" 'Change this to the correct path for your machine
Dim RegName As String
RegName = InputBox("What Region to Move?")
Dim Aname As String
Aname = RegName
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=RegName & ".xls"
Dim TargWb As Workbook
Set TargWb = Workbooks(RegName & ".xls")
Dim lr2 As Long
lr2 = TargWb.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
wb.Activate
Sheets("Sheet1").Range("B1:G1").Copy TargWb.Sheets("Sheet1").Range("A1")
For i = 2 To lr
lr2 = TargWb.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
If Sheets("sheet1").Range("B" & i) = RegName Then
Sheets("Sheet1").Range("B" & i & ":G" & i).Copy TargWb.Sheets("Sheet1").Range("A" & lr2 + 1)
End If
Next i
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox "complete"
End Sub
How to install your new code
- Copy the Excel VBA code
- Select the workbook in which you want to store the Excel VBA code
- Press Alt+F11 to open the Visual Basic Editor
- Choose Insert > Module
- Edit > Paste the macro into the module that appeared
- Close the VBEditor
- Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
To run the Excel VBA code:- Press Alt-F8 to open the macro list
- Select a macro in the list
- Click the Run button
Bookmarks