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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,473
Messages
6,130,838
Members
449,597
Latest member
buikhanhsang

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