Creating sheets with pasted colour-marked rows through a nifty macro command, please
Arsaces wrote:
I have an Excel spreadsheet that seems quite simple to work with. The
catch? I've got tens of these to work with on a daily basis.
The idea is generally that I have this spreadsheet for monitoring orders
on a certain batch. After 14 days, we determine if the orders were
confirmed or if they were canceled whereas the orders are sorted in
their own sheets (confirmed and canceled).
Generally, this is the process I have in mind: I use colour coding, good
row or bad row to distinguish between rows. Green in this case
represents confirmed orders, whereas red represents canceled orders.
Now, through a macro of some sorts, two new sheets are created, where
each set of rows are copied and pasted.
The sheet of confirmed orders is essentially the same as the previous
sheet (With all the entries), except it has only the green rows pasted
into it, while the sheet for canceled orders should only have the red
rows.
Now, in case it's required, here is the plain Excel file that I work
with. It's "original.jpg"
In the files, "whatiwantittodo" 1 through 4 is what I want it to look
like. Currently this is all done by hand.
What I would like is, when I do the colour-marking, and then (When I am
finished applying the colour-formatting on the rows) input a macro, the
rows are copied into two newly auto-created sheets, where good entries
(green) are pasted into one of the sheets, and the bad entries (red) are
pasted into the other sheet.
So in pseudo-code sense, I essentially want this:
while row=green
mark selection
copy row
create sheet
goto sheet
paste selection
And vice versa if it's for red rows.
I would really want to find a way to optimize this process through a
handy macro. It would be a real time-saver. Can anyone please help me? I
am using Excel 2010 on Windows 7.
Try this. (Probably not the best way to do it, but it works for me under
2007.)
Sub makeReports()
Dim current As Worksheet, confirmed As Worksheet, canceled As Worksheet
Set current = ActiveSheet
'Create the new sheets.
'Names include timestamp. This allows multiple reports if necessary.
when = Format(Now, "yyyymmdd-hhmmss")
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "Confirmed (" & when & ")"
Set confirmed = Sheets(Sheets.Count)
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "Canceled (" & when & ")"
Set canceled = Sheets(Sheets.Count)
'Copy the headings row.
current.Cells(1, 1).EntireRow.Copy
confirmed.Select
confirmed.Cells(1, 1).Select
ActiveSheet.Paste
canceled.Select
canceled.Cells(1, 1).Select
ActiveSheet.Paste
'The actual work.
For L0 = 2 To current.Cells.SpecialCells(xlCellTypeLastCell).Row
Select Case current.Cells(L0, 1).Style
Case "Good"
current.Cells(L0, 1).EntireRow.Copy
confirmed.Select
confirmed.Cells(confirmed.Cells.SpecialCells _
(xlCellTypeLastCell).Row + 1, 1).Select
ActiveSheet.Paste
Case "Bad"
current.Cells(L0, 1).EntireRow.Copy
canceled.Select
canceled.Cells(canceled.Cells.SpecialCells _
(xlCellTypeLastCell).Row + 1, 1).Select
ActiveSheet.Paste
End Select
Next
'Not strictly necessary, but the marching ants bother me.
Application.CutCopyMode = False
End Sub
This assumes that you *always* use the "Good" and "Bad" styles, instead of
coloring the rows manually (or whatever).
--
Family are the worst customers!
|