rickbisselink

Board Regular
Joined
Oct 16, 2007
Messages
146
L.S.,

I am trying to populate column P with a formula that exists in cell P5. The number of rows is variable and is dependent on the number of rows in column A. As column P is pre-populated, it might be longer or shorter than column A before running the code. It should end up with the same length as column A. I repeat this for several sheets.

I get a runtime error 1004 (method range of object _worksheet failed) in the 7th line below. Can anybody help me out?

Thanks,
Rick

Code:
  With wsActual
    LastRowA = .Cells(.Rows.Count, "A").End(xlUp).Row
    LastRowP = .Cells(.Rows.Count, "P").End(xlUp).Row
    .Range("P5:P" & LastRowA).FillDown
    If LastRowP > LastRowA Then
      LastRowA = LastRowA + 1
      .Range(Cells(LastRowA, 16), Cells(LastRowP, 16)).ClearContents
    End If
  End With
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I think you ned to call .Cells within the parenthesis again

Code:
  With wsActual
    LastRowA = .Cells(.Rows.Count, "A").End(xlUp).Row
    LastRowP = .Cells(.Rows.Count, "P").End(xlUp).Row
    .Range("P5:P" & LastRowA).FillDown
    If LastRowP > LastRowA Then
      LastRowA = LastRowA + 1
      .Range([COLOR=#ff0000].Cells[/COLOR](LastRowA, 16), [COLOR=#ff0000].Cells[/COLOR](LastRowP, 16)).ClearContents
    End If
  End With
 
Upvote 0
You need to put a . infront of the word Cells (both of them)
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,824
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top