Simplemountain
New Member
- Joined
- Feb 26, 2016
- Messages
- 27
Ok,
I know that this is a subject that comes up over and over again and I assure you that I have spent countless hours going over posts that answer this question in different ways. Yet, I am having some true difficulty putting all of the pieces together to create a macro that works the way I truly need. I am repeatedly amazed at the charity of the people on this forum and want to say thank you to everyone who contributes and is involved. It is truly an incredible resource. Thank you!!
So here is where I'm at:
I have some raw data that is imported into an excel sheet from an external program for instruments that require calibration (about 1000 or so) I call this sheet the master. The data contains rows which represent one item. Each item has several columns of information pertinent to that item (serial#, Calibration date, description, etc...). I am working on breaking the data down into separate sheets based on departments so that each department can easily see what instruments are coming due for calibration. Currently there is no designation for department but I will gradually update the data to include column "L" which will represent the department each item belongs to. I am trying to create a macro that looks at column "L" and creates a sheet for each department and then populates the data from the master sheet into the department sheet for each item that belongs there.
currently I have the following macro:
Sub MigrateData()
Application.ScreenUpdating = False
Dim lRow As Long
Dim MySheet As String
lRow = Range("A" & Rows.Count).End(xlUp).Row
For Each sht In Worksheets
If sht.Name <> "Master" Then
sht.UsedRange.Offset(1).ClearContents
End If
Next sht
For Each cell In Range("L6:L" & lRow)
MySheet = cell.Value
cell.EntireRow.Copy Sheets(MySheet).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Next cell
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
This works great for populating data to a known sheet name.
I would like the macro to eventually do this:
The workbook begins with one sheet (sheet 1) called 'Master' containing the raw data. The macro will create new sheets based on a known list (Dept 1, Dept 2, Dept 3, etc...) There will also be an additional sheet called unclassified. The macro will then look at column "L" on the master sheet. This column will have a value that corresponds to the known department names (Dept 1, Dept 2, Dept 3, etc...) For any value that is the same as a known department name it will then copy that row to the appropriate sheet of the same name. For any value that is blank or not equal to one of the predetermined sheet names, it will copy that row into the sheet labeled 'unclassified'. I picture this being something to the effect of 'On error, copy row to unclassified'
The reason for all of this is that I will be assigning departments over a stretch of time and need to be able to split the data to each department sheet they are assigned to while also having a sheet that includes all of the items that are not currently assigned to a department.
Eventually, I will also be attempting to get the final data on each sheet into a table format so that I can easily reorganize the data based on the value of each column. The end game is to have conditional formating for the calibration due date (column "H") on each sheet that colors a cell based on how soon calibration is required. This will allow each department to see exactly what equipment needs to be looked at on a monthly basis. I will be generating new sheets based on the raw data monthly which is why I am trying to streamline the process using VBA.
Thank you in advance to any and all who read through all of this and have any ideas!!
I know that this is a subject that comes up over and over again and I assure you that I have spent countless hours going over posts that answer this question in different ways. Yet, I am having some true difficulty putting all of the pieces together to create a macro that works the way I truly need. I am repeatedly amazed at the charity of the people on this forum and want to say thank you to everyone who contributes and is involved. It is truly an incredible resource. Thank you!!
So here is where I'm at:
I have some raw data that is imported into an excel sheet from an external program for instruments that require calibration (about 1000 or so) I call this sheet the master. The data contains rows which represent one item. Each item has several columns of information pertinent to that item (serial#, Calibration date, description, etc...). I am working on breaking the data down into separate sheets based on departments so that each department can easily see what instruments are coming due for calibration. Currently there is no designation for department but I will gradually update the data to include column "L" which will represent the department each item belongs to. I am trying to create a macro that looks at column "L" and creates a sheet for each department and then populates the data from the master sheet into the department sheet for each item that belongs there.
currently I have the following macro:
Sub MigrateData()
Application.ScreenUpdating = False
Dim lRow As Long
Dim MySheet As String
lRow = Range("A" & Rows.Count).End(xlUp).Row
For Each sht In Worksheets
If sht.Name <> "Master" Then
sht.UsedRange.Offset(1).ClearContents
End If
Next sht
For Each cell In Range("L6:L" & lRow)
MySheet = cell.Value
cell.EntireRow.Copy Sheets(MySheet).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Next cell
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
This works great for populating data to a known sheet name.
I would like the macro to eventually do this:
The workbook begins with one sheet (sheet 1) called 'Master' containing the raw data. The macro will create new sheets based on a known list (Dept 1, Dept 2, Dept 3, etc...) There will also be an additional sheet called unclassified. The macro will then look at column "L" on the master sheet. This column will have a value that corresponds to the known department names (Dept 1, Dept 2, Dept 3, etc...) For any value that is the same as a known department name it will then copy that row to the appropriate sheet of the same name. For any value that is blank or not equal to one of the predetermined sheet names, it will copy that row into the sheet labeled 'unclassified'. I picture this being something to the effect of 'On error, copy row to unclassified'
The reason for all of this is that I will be assigning departments over a stretch of time and need to be able to split the data to each department sheet they are assigned to while also having a sheet that includes all of the items that are not currently assigned to a department.
Eventually, I will also be attempting to get the final data on each sheet into a table format so that I can easily reorganize the data based on the value of each column. The end game is to have conditional formating for the calibration due date (column "H") on each sheet that colors a cell based on how soon calibration is required. This will allow each department to see exactly what equipment needs to be looked at on a monthly basis. I will be generating new sheets based on the raw data monthly which is why I am trying to streamline the process using VBA.
Thank you in advance to any and all who read through all of this and have any ideas!!