Hi! I am creating a macro that will create separate sheets for each department in my company based on a range in a sheet with all source data. This works fine. It creates a sheet for each department in the selected range, but what I really need is to have all the records for that department also in the respective sheet. I have over 50 departments, so doing this manually is way too time consuming. Below is the current macro that I am using to create the sheets. Any and all help is appreciated.
Code:
Option Explicit
Sub Create_Dept_ws()
Dim rng As Range
Dim cell As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Enable error handling
On Error GoTo Errorhandling
'Show inputbox to user and prompt for a cell range
Set rng = Application.InputBox(Prompt:="Select cell range:", Title:="Create sheets", Default:=Selection.Address, Type:=8)
'Iterate through cells in selected cell range
For Each cell In rng
'Check if cell is not empty
If cell <> "" Then
'Insert worksheet and name the worksheet based on cell value
Sheets.Add.Name = "EEs - " & cell
End If
Next cell
'Go here if an error occurs
Errorhandling:
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub