Selection Error

  • Thread starter Thread starter Ripan
  • Start date Start date
R

Ripan

I am writing a macro that copies rows from one workbook into a ne
workbook if they satisfy a condition. I have a loop as follows:

With ActiveWorkbook.Worksheets("Master Input")
Do While .Cells(i, 1).Value <> ""
If <Condition> Then
.Rows(i).Select 'ERROR LINE
Workbooks("Data Capture").Activate
Worksheets("Master Input").Activate
Range(.Cells(rowPos)).PasteSpecial xlPasteValues
Workbooks(filename).Activate
rowPos = rowPos + 1
End If
i = i + 1
Loop
End With

The .Rows(i).Select command gives me the following error message:

Select Method of Range Class Failed.

Any help on how to fix this error?

Thank
 
Hi
how is 'i' defined prior to this command. Maybe its '0' -> an error
would occur
 
You can't select a range on a sheet unless that sheet is active.

with activeworkbooks.worksheets("master input")
.select
do while....

it looks like you're doing some kind of copy|paste special|values.

I'm not sure where things were copied from, but maybe you could just assign the
value and get rid of all the .selects/activates:

with worksheets("master input")
.range(somerange).value _
= workbooks("data capture").worksheets("master input").range(somerange).value
end with


but I'm confuse about the from/to locations.
 

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

Back
Top