JLatham said:
The missing line of code was a test, you passed <g>. Sorry about
that.
Here's a routine you could add in the same module with what you
have and then call right after the Next that ends the copying
routine and before the formatting code you've added to deal with
the entries with Canceled in column A.
Very interesting. I learned a couple of things, including about
private macros; I hadn't known how they worked. I am keeping
your code around to refer to for more learning. I have
one question about it so far: the word that is in the rows
I want to delete in Column A is cased as follows: "Cancel".
So I'd have to take the uppercase directive out or change it.
Also, the trim thing is a nice touch and I appreciated seeing it.
It doesn't seem necessary in the particular instance of this data,
but it's still good for me to know.
Now I have to confess something, but I hope you won't feel like
your help was in vain, because it certainly wasn't. But while
I was waiting and hoping for more help I looked around on the
web and I found, e.g., this:
http://www.mvps.org/dmcritchie/excel/delempty.htm
Down low on that page he has this section:
Delete rows with "N" in Column 31 (#Delete_N_MarkedRows)
Sub Delete_N_MarkedRows()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim lastrow As Long, r As Long
lastrow = ActiveSheet.UsedRange.Rows.Count
For r = lastrow To 1 Step -1
If UCase(Cells(r, 31).Value) = "N" Then Rows(r).Delete
Next r
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
I thought, "Hey, I bet I can alter that for my needs." I see he
uses the UCase thing as you have, too. Anyway, I thought about
it and realized we are done with the main loop of the macro and I
still have your "sRow" integer sitting around, so I don't even need
another variable. I decided I could just stick a new For-loop in
front of the other (formatting) stuff I'm doing post-copy. I
removed the UCase, but I don't know how to specify case-sensitive
for "Cancel"; but in this case there is not going to be anything
similar there anyway. (I'd still like to know how to specify case,
though.)
Anyway, here's what I have now after the Next-statement in
the main macro. this deletion stuff and all the formatting
have gone in this section.
'/* dman
' delete rows with "Canceled" in Col A
For sRow = lastRow(DestSh) To 1 Step -1
If Cells(sRow, 1).Value = "Canceled" _
Then Rows(sRow).Delete
Next sRow
' format stuff
DestSh.UsedRange.Select
With Selection
.Columns.WrapText = False
.Columns.AutoFit
.Interior.ColorIndex = xlNone 'unformat
Application.CutCopyMode = False
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=MOD(ROW(),2)"
.FormatConditions(1).Interior.ColorIndex = 24
End With
DestSh.Range("A1:F2").Select
With Selection
.Hyperlinks.Delete
.FormatConditions.Delete
.Interior.ColorIndex = 37
.HorizontalAlignment = xlCenter
.Font.FontStyle = "Bold"
.Font.ColorIndex = 11
End With
Range("F1:F2").Columns.AutoFit
'dman */
Well, I don't know, stylistically, just how kosher that is,
but it works!
And with your help, the learning curve has been fun so far.
My next task will be to take Column C's data and run it
through Text-to-Columns, adding several columns. I'll have
to insert some blank columns after C first to keep data
in remaining columns from being overwritten. Then I'll
have to get the column widths right again.
Here is an example of what's in Column C. You'll see
why I want to separate the words.
Buy 100 AMD Limit 14.25 GTC DNR
Actually, the "GTC DNR" ("Do Not Reduce") part could
be in a single column, but it's more trouble than it's
worth to do that while separating all the other words
via Text-to-Columns.
Dallman
===================================
JLatham said:
Not knowing how things are formatted up before you do the
copies, I'd say what you have is probably as good as anything
else, with the point being that it ends up formatted as you
require.
The missing line of code was a test, you passed <g>. Sorry about
that.
Here's a routine you could add in the same module with what you
have and then call right after the Next that ends the copying
routine and before the formatting code you've added to deal with
the entries with Canceled in column A. I've set it up to start
removing rows at row 3, since rows 1 and 2 are header information
you probably want to keep. I have made it Private to keep it
out of the list of available macros to be run from the Tools |
Macro | Macros feature. Just add this line of code after the
Next statement in your existing code from Ron's site:
RemoveCanceledEntries
Application.ScreenUpdating = False
I added the Application.ScreenUpdating = False statement because
exiting the RemoveCanceledEntries routine will reset it to True
and this will keep things going smoothly without eating up time
refreshing the display while you do your formatting.
Here's the code:
Private Sub RemoveCanceledEntries()
Dim rOffset As Long
Dim baseCell As Range
Set baseCell = Worksheets("MergeSheet").Range("A3")
Application.ScreenUpdating = False
Do Until IsEmpty(Range("A3").Offset(rOffset, 0))
'spelling must be same and in UPPERCASE here
If UCase(Trim(baseCell.Offset(rOffset, 0))) = "CANCELED" Then
baseCell.Offset(rOffset, 0).EntireRow.Delete
rOffset = rOffset - 1 ' stay here
End If
rOffset = rOffset + 1
Loop
End Sub
Hope this helps and is less frustrating than my first offering.
:
[snip]