autofill down error

papajups

Board Regular
Joined
Sep 8, 2012
Messages
166
Hi,


I would like to seek for any help regarding below codes:

Code:
Range("E3:F3").Autofill Destination:=Range("E3:F" & Cells(Rows.Count, "A").End(xlUp).Row)

My concern is if column A is totally empty and someone attempt to click the button that contains the above macro then all the headers above (E3 and F3 will be messed up, they will also turn into formula.

I humbly ask you to please help me with this one. I wish to have a revised codes that even though I have empty column A and someone attempt to click the button with macro, my headers will not be cleared and turn into formula.

Please help me.

Any help will be highly appreciated. thanks a lot in advance!


best regards,


papajups
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi,

One option might be something like:

Code:
Dim lr As Long

lr = Cells(Rows.Count, "A").End(xlUp).Row
If lr > 3 Then
    Range("E3:F3").AutoFill _
        Destination:=Range("E3:F" & lr)
End If
 
Upvote 0
I can think of two alternatives to handle this:
1. If column A is empty, do not run the autofill line
2. Instead of using column A to find the last row of data, look for the last row of data in the used range.

Would one of these work for you?
 
Upvote 0
Code:
[COLOR=darkblue]With[/COLOR] Cells(Rows.Count, "A").End(xlUp)
    [COLOR=darkblue]If[/COLOR] .Row > 3 [COLOR=darkblue]Then [/COLOR]Range("E3:F3").AutoFill Destination:=Range("E3:F" & .Row)
End [COLOR=darkblue]With[/COLOR]
 
Last edited:
Upvote 0
Hi circledchicken,


A pleasant day!

The codes you have shared are amazing. This one works. Thanks a lot for your help... More power!


-papajups
 
Upvote 0
Hi Alphafrog,


I also want to thank you deep inside me for sharing your knowledge, for helping me out with this concern. Above codes are great and will definitely make improvements in our file. Thank you so much. God bless!


-papajups
 
Upvote 0

Forum statistics

Threads
1,213,529
Messages
6,114,155
Members
448,554
Latest member
Gleisner2

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