AutoFill method error

Tur3n

New Member
Joined
Jul 14, 2022
Messages
11
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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Adding screenshot how excel file looks before error:

1657794373676.png
 
Upvote 0
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
 
Upvote 0
Solution
Hi Fluff,
seems it's working perfectly, thanks a lot ! :)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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