VB - Varible Parameters

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi...

My Calling Statement:

Call CheckFields(5,1,3,4,2,7)

I have the following code in a Module

Public Sub CheckFields(NumberOfColumns, SearchColumn1, SearchColumn2, SearchColumn3, SearchColumn4, SearchColumn5)

Dim TargetColumns As Variant

ReDim TargetColumns(NumberOfColumns - 1)

For i = 0 to NumberOfColumns -1

TargetColumns(i) = ?????

Next

.
.
.
End Sub

I tried using SearchColumn & i + 1 at the ????? but all I get in my array are the values 1 through 5 and not what is contained in SearchColumn 1 thru SearchColumn5.

Is there a way to loop through the names of the SearchColumn's defined in the Sub statement?

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Do you want to pass a undetermined amount of arguments for SearchColumn?
Code:
Public Sub CheckFields(ParamArray SearchColumns())
Dim I As Long
    For I = LBound(SearchColumns) To UBound(SearchColumns)
    
        MsgBox SearchColumns(I)
        
    Next I
End Sub
I've not included NumberOfColumns, not sure it's still needed.

You can add it back into the parameter list, just put it at the start.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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