VBA Help - errors with only 1 row of data

danny8890

New Member
Joined
Feb 7, 2018
Messages
46
Hi,

I've got a piece of code that autofills the sheet when run macro it works perfectly fine unless the sheet has only got 2 rows of data (header row and a data row).

I feel i'm missing something quite simple if someone could help me so the auto fill will start from row 2 and auto fill either just the 1 row if data is there or do as many rows are in the sheet.

Code:
sh.Range("H2:N2").AutoFill Destination:=sh.Range("H2:N" & sh.Range("A" & Rows.Count).End(xlUp).Row)

Thanks in advance
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You could do:

Code:
lr = sh.Range("A" & Rows.Count).End(xlUp).Row
If lr > 2 Then sh.Range("H2:N2").AutoFill Destination:=sh.Range("H2:N" & lr)
 
Upvote 0

Forum statistics

Threads
1,203,060
Messages
6,053,303
Members
444,650
Latest member
bookendinSA

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