Why need to use Selection.PasteSpecial vs myRange.PasteSpecial

E

EagleOne

2003/2007

This code works:
Dim SrchAcctRng as Range

SrchAcctRng.Select
SrchAcctRng.Copy
Selection.PasteSpecial xlPasteValues

Next code fails in range class
Dim SrchAcctRng as Range

SrchAcctRng.Copy
SrchAcctRng.PasteSpecial xlPasteValues

Note that SrchAcctRng is a filtered range as a result of:

Set SrchAcctRng = wks.Range(Cells(PrintRow + 1, PrintCol).Address, _
Cells(wks.Cells(Rows.Count, 1).End(xlUp).Row - 1, PrintCol)).SpecialCells(xlCellTypeVisible)


I do not usderstand why I need to use Selection.PasteSpecial xlPasteValues?

TIA EagleOne
 
M

Mark Lincoln

What happens if you add:

SrchAcctRng.Select

to the second example?

Mark Lincoln
 
G

Gary Keramidas

this works for me:

Sub test()
Dim ws As Worksheet
Dim SrchAcctRng As Range
Set ws = Worksheets("sheet1")
Set SrchAcctRng = ws.Range("A1:C2")
SrchAcctRng.Copy
SrchAcctRng.PasteSpecial xlPasteValues
End Sub
 
G

Gary Keramidas

sorry, didn't see the filtered range

--


Gary


Gary Keramidas said:
this works for me:

Sub test()
Dim ws As Worksheet
Dim SrchAcctRng As Range
Set ws = Worksheets("sheet1")
Set SrchAcctRng = ws.Range("A1:C2")
SrchAcctRng.Copy
SrchAcctRng.PasteSpecial xlPasteValues
End Sub
 
E

EagleOne

Thanks for the thoughts.

Here is what I found:

Using 2007, I had not enabled macros (prompt at open) for the WB in which I was "processing" with
VBA.

When I would get a "macros not enabled" notice, I would reselect Personal.xls in the VBE Explorer
and continue editing as if nothing was wrong.

By not enabling macros in the object w/b, "some" - but not all - of the VBA code would process.

In short, If I enabled macros re: the object w/b in 2007, all VBA works fine. If not, only some VBA
worked.

Thanks EagleOne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top