View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Should be easy...what's missing?

Okay, I looked at your code a little more closely... the problem you are
having is because you are trying to select cells from a non-active
worksheet... you can't do that... and you don't have to. Look at AB's and
FSt1's responses to see how not to rely on selecting cells before you
perform operations with them.

Perhaps this previous posting of mine (a response to another person using
Select/Selection type constructions) will be of some help to you also...

Whenever you see code constructed like this...

Range("A1").Select
Selection.<whatever

you can almost always do this instead...

Range("A1").<whatever

In your particular case, you have this...

Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows

which, using the above concept, can be reduced to this...

For Each r In Range("C2:C8193").Rows

Notice, all I have done is replace Selection with the range you Select(ed)
in the previous statement and eliminate the process of doing any
Select(ion)s. Stated another way, the Selection produced from
Range(...).Select is a range and, of course, Range(...) is a range... and,
in fact, they are the same range, so it doesn't matter which one you use.
The added benefit of not selecting ranges first is your active cell does not
change.

--
Rick (MVP - Excel)



"MovingBeyondtheRecordButton"
.com wrote in message
...
Using c.Select resulted in a run-time error '1004 Select method of range
class failed

"Rick Rothstein" wrote:

Address is a String value... you can't select a String. Try just c.Select
and see if that works for you.

--
Rick (MVP - Excel)



"MovingBeyondtheRecordButton"
.com wrote in message
...
Code doesn't work due to error on line: c.Address.Select

With Worksheets("Sheet2").Range("G2:G76")
Set c = .Find(F.Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Worksheets("Sheet3").Range("Q2:V2").Select
Application.CutCopyMode = False
Selection.Copy
c.Address.Select
ActiveCell.Offset(0, -6).Range("A1").Select
ActiveSheet.Paste
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

I want to..

1) find where F.Value = the Value of a cell in
Worksheets("Sheet2").Range("G2:G76")
2) paste values from cells Worksheets("Sheet3").Range("Q2:V2") into
columns
A through F (in the same row as the cell that was just found in .Find)

.