IF Not ISEmpty Autofill problem

RaydenUK

Board Regular
Joined
Mar 25, 2014
Messages
74
I have a macro that will autofill column C with the contents of "C1" to the last used row from column A. This code works great unless row 1 is the only row. That is why I used "If Not IsEmpty("A2") Then" because I wanted it to recognize that if "A2" is empty then do not autofill. When i use this code on only 1 row then i get the error "1004: Autofil method of range class failed". Can anyone help me out with this code? Thank you.

Code:
Sub UsedRange()

    Dim lastrow As Long
    
   If Not IsEmpty("A2") Then
       lastrow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
       Range("C1").AutoFill Range("C1:C" & lastrow), xlFillCopy
   End If


End Sub
 
HA! It Works! i was putting your line of code in the wrong place. Like I said I'm still new at it. This will help me out tremendously. Thank you for your patience and all your help.
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,216,073
Messages
6,128,641
Members
449,461
Latest member
kokoanutt

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