Hi guys, need some help here!

maramos

New Member
Joined
Jan 9, 2023
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

Ik have found this it does almost what i need to do.

There is a formula row R11:Z11. VBA wil find the last empty rows and paste the formula there. The problem is that it does copy the exact row numbers starting row R11 then R12 etc.
I need it to just copy and use the row numbers where it is copied. I hope someone can help me with this.

Thanks,


Sub Fill_only_empty()

Dim LR As Long

LR = ActiveSheet.UsedRange.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row

With Range("R12:Z" & LR)
With .SpecialCells(xlCellTypeBlanks)
.Formula = Range("R11:Z11").Formula
End With
.Value = .Value
End With

End Sub
 
You could change the formulas to refer to relative row addresses by using an Indirect/Address combination - in which case you could leave your VBA code exactly as it is & the formulas would follow the rows wherever they were copied to. So for example, your formula in cell S11 (Shipping Month) could be changed from this:
Excel Formula:
=+YEAR(P11)&"-"&IF(MONTH(P11)<10;"0"&MONTH(P11);MONTH(P11))
to this:
Excel Formula:
=YEAR(INDIRECT(ADDRESS(ROW();16;3)))&"-"&TEXT(MONTH(INDIRECT(ADDRESS(ROW();16;3)));"00")

And your formula in cell V11 (KPI Country) could be changed from this:
Excel Formula:
=+IF(F11="SM";"IT";F11)&S11&Q11&D11
to this:
Excel Formula:
=IF(INDIRECT(ADDRESS(ROW();6;3))="SM";"IT";INDIRECT(ADDRESS(ROW();6;3)))&INDIRECT(ADDRESS(ROW();19;3))&INDIRECT(ADDRESS(ROW();17;3))

Can you see where the absolute cell references in your original formulas are converted - for example P11 becomes INDIRECT(ADDRESS(ROW();16,3)) where ROW() refers to the current row (i.e. the row that the formula is sitting on) and 16 refers to column 16 (which is column P) and 3 simply means that the row reference should be relative but the column reference is absolute. I tested some formulas in your layout & the copied formulas did move their references to the rows they were then sitting on (copied to) so this method will work.

I can't fully test your code because I don't have anything like what your first formula in cell R11 refers to, but you could convert your formulas if you see it as worth it. Please note also that you don't need to add a plus sign + after the equals sign = in your formulas. I'm afraid that's all I can offer you, but perhaps a better solution will come along.

Another example of how to convert your formulas is your formula in cell U11 (KPI Carrier Country) could be changed from this:
Excel Formula:
=+R11&S11&Q11&F11
to this:
Excel Formula:
=INDIRECT(ADDRESS(ROW();18;3))&INDIRECT(ADDRESS(ROW();19;3))&INDIRECT(ADDRESS(ROW();17;3))&INDIRECT(ADDRESS(ROW();6;3))
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi thanks,

I have change the rest and they work fine only this formula i need to change. The R11. I have made it a little easy. Can you check it out for me.

=IFERROR(VLOOKUP(H11;Carriers!A:D;3;FALSE);"")
 
Upvote 0
Hi thanks,

I have change the rest and they work fine only this formula i need to change. The R11. I have made it a little easy. Can you check it out for me.

=IFERROR(VLOOKUP(H11;Carriers!A:D;3;FALSE);"")
It looks OK. To be consistent with the other suggestions you would replace the H11 with:
INDIRECT(ADDRESS(ROW();8;3)) where 8 is column H.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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