View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default macro help please

One way around a problem like this is to not select ranges. But the bad news is
that excel sees a .pastespecial as a selection change. Same thing with the
specialcells stuff.

So you could tell excel to stop monitoring events (like selection changes) right
before you change selection--and tell it to start again when you're done.

Option Explicit
Sub copy1()

Dim DestCell As Range
Dim RngToCopy As Range

With ActiveSheet
Set RngToCopy = .Range("A3:AX1006")
End With

With Worksheets("Month One")
Set DestCell = .Range("a3")
End With

RngToCopy.Copy
With DestCell
Application.EnableEvents = False
.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.EnableEvents = True
End With

Application.EnableEvents = False
Sheets("Month One").Range("B6:B1006") _
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Application.EnableEvents = True

With Worksheets("suggestions")
Set RngToCopy = .Range("a5:z1000")
End With

With Worksheets("Suggested Changes")
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

RngToCopy.Copy
With DestCell
Application.EnableEvents = False
.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.EnableEvents = True
End With

With DestCell.Resize(RngToCopy.Rows.Count, RngToCopy.Columns.Count)
.Replace What:="", Replacement:="$$$$$", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
.Replace What:="$$$$$", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With

'keep the events enabled here!
With Worksheets("suggested Changes")
Application.Goto .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

End Sub

============

You could actually just turn event monitoring off at the top and and then turn
it back on at the bottom. But as a personal preference, I usually (depending on
the mood I'm in!) like to toggle it off right before it would have fired and
turn it back on right after I'm done hiding from that event.

I think that it makes it a little easier to steal code from old projects, too.
I won't miss what I need when I copy|Paste.

============

And as newsgroup response, I think it's better to start a new thread when the
original question is resolved--but not before. I (as well as most regulars)
hate seeing a new post when there's an active thread elsewhere.

============

And I'll leave any remuneration discussions between you and my financial
manager, Gord!

Ryk wrote:

Well, I think that all works, gonna try it a few times. As I am new to
posting here and have not be explained the rules, if I have further
questions, should I just keep adding to this one or post a new one?
other question probably easy enough tho, i am using a row
highlighter....

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Const cnNUMCOLS As Long = 256
Const cnHIGHLIGHTCOLOR As Long = 36 'default lt. yellow
Static rOld As Range
Static nColorIndices(1 To cnNUMCOLS) As Long
Dim i As Long
If Not rOld Is Nothing Then 'Restore color indices
With rOld.Cells
If .Row = ActiveCell.Row Then Exit Sub 'same row, don't
restore
For i = 1 To cnNUMCOLS
.Item(i).Interior.ColorIndex = nColorIndices(i)
Next i
End With
End If
Set rOld = Cells(ActiveCell.Row, 1).Resize(1, cnNUMCOLS)
With rOld
For i = 1 To cnNUMCOLS
nColorIndices(i) = .Item(i).Interior.ColorIndex
Next i
.Interior.ColorIndex = cnHIGHLIGHTCOLOR
End With
End Sub

This works just fine, put I have made a copy macro and this interferes
with it a bit, Can i make buttons, that turn a macro on or off? If so
i'd just add the off part to existing... hmmmmmm, i'll add the copy
macro as well, just in case it can be added to shut off the macro while
it copies.

Sub copy1()
'
' copy1 Macro
' Macro recorded 8/22/2006 by ryk'
' Keyboard Shortcut: Ctrl+o
'
Range("A3:AX1006").Select
Selection.Copy
Sheets("Month One").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Sheets("Month One").Select
Range("A1").Select
Selection.Copy
Sheets("Month One").Select
Range("A1").Select
ActiveSheet.Paste
Range("B6:B1006").SpecialCells(xlCellTypeBlanks).E ntireRow.Delete
Sheets("Suggestions").Select
Range("A5:Z1000").Select
Selection.Copy
Sheets("Suggested Changes").Select
Range("A1").Select
mycell = Cells(Rows.Count, "A").End(xlUp).Row + 1
Range("A" & mycell).Select
Selection.PasteSpecial Paste:=xlPasteFormats,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteColumnWidths,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.Replace What:="", Replacement:="$$$$$",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="$$$$$", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
mycell = Cells(Rows.Count, "A").End(xlUp).Row + 1
Range("A" & mycell).Select

End Sub

If I cannot do on/off for macro I can lose the highlighter, it just
helps because we spend alot of hours a week staring at this program
hehe. More important the copy works, as we remove all the formulas so
we can send out smaller sized files.

Dave, if you answer this, please enlighten me on posting politeness if
I am doing this wrong, as I have really gained alot and don't wish to
**** anyone off heheh.

Many thanks for what you have helped me with though, i hope you get
paid somehow to do this.

Dave


--

Dave Peterson