VBA array with variable rows

uti1301

New Member
Joined
Jul 17, 2017
Messages
18
I have an array with 5 columns and variable rows. I am using Vlookup, which works for the array I have, with 5 columns and 13 rows.
The code is as follows:
SUB macro1()
Range("F2").select
activecell.formulaR1C1="=IFERROR(Vlookup(RC[-1],R2C1:R13C5,4,FALSE),0)"
Range("F2").select
Selection Autofill Destination:=Range("F2:F13",Type:=xlFillDefault
Range("F2:F13").select
end sub

However the rows are variable.
I would be very grateful if someone could tell me how to do this for any number of rows

Thanks in advance for any ideas
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Re: VBA arraywith variable rows

Try
Code:
Sub macro1()
Dim UsdRws As Long
UsdRws = Range("[COLOR=#ff0000]E[/COLOR]" & Rows.Count).End(xlUp).Row
With Range("F2:F" & UsdRws)
    .Formula = "=IFERROR(Vlookup(E2,A$2:E$" & UsdRws & ",4,FALSE),0)"
End With
End Sub
I've used col E to find the last used row.
 
Upvote 0
Re: VBA arraywith variable rows

Thank you very much Fluff. I think this will work perfectly. I actually worked out how to do it, but your code looks better than mine, so I will use yours.
Thanks again
 
Upvote 0
Re: VBA arraywith variable rows

Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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