AutoFill method error

Tur3n

New Member
Joined
Jul 14, 2022
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Hi All,
I won't hide this, I'm starting adventure with VBA now.

Someone from company has created below macro - I wanna to develop it.
If there is more rows, then auto fill is working. If one row or nothing, then I see following error:

1657794017648.png


So, how to fix it ? Current macro looks as following:

VBA Code:
Range("D2").Select
    ActiveCell.Value = today
    Selection.AutoFill Destination:=Range("D2:D" & last_row), Type:=xlFillDefault
    
    Range("E2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]>RC[-3]"
    Selection.AutoFill Destination:=Range("E2:E" & last_row), Type:=xlFillDefault

As you can see: Delivery No. is dynamic. Sometimes I need to update values in SAP for 1 delivery no, sometimes we have more.. and from time to time there is nothing to update.
To prepare upload file I need to get working VBA code. Above generates error as I attached.


Any clue what should be added/changed in above ?

Thanks in advance,
Adam
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Tur3n

New Member
Joined
Jul 14, 2022
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Adding screenshot how excel file looks before error:

1657794373676.png
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
77,722
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
If last_row > 1 Then
   Range("D2:D" & last_row).Value = today
   Range("E2:E" & last_row).FormulaR1C1 = "=RC[-1]>RC[-3]"
End If
 
Solution

Tur3n

New Member
Joined
Jul 14, 2022
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Hi Fluff,
seems it's working perfectly, thanks a lot ! :)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
77,722
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,176,196
Messages
5,901,852
Members
434,924
Latest member
husamco

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
Top