0

I have a function which collects which months are ticked in a user form, containing checkboxes:

Function get_entries() As Boolean()

This returns a 2D boolean array(4, 11) representing 5 x 12 check boxes, which in turn represents months that are selected from a userform

In my main function:

Dim montharr() As Boolean
montharr = get_entries()

Call myfunc1(montharr(0))
Call myotherfunc(montharr(1))
Call myotherfunc(montharr(2))
Call myotherfunc(montharr(3))
Call myotherfunc(montharr(4))

I can't pass in the individual arrays of 12 elements to the subs successfully. I have tried declaring items as variants too but this isn't working and have spent ages trying to get this to work. Any thoughts welcome.

1
  • you should create new 1D array with values montharr(0,1), montharr(0,2) and so on and pass it in the myotherfunc Commented Mar 29, 2014 at 19:50

1 Answer 1

1

Here's one way to "slice" a 2-D array:

Sub ArraySlicing()

Dim arr(1 To 5, 1 To 5)
Dim slice
Dim x, y
Dim a As Application

    For y = 1 To 5
    For x = 1 To 5
        arr(y, x) = "R" & y & ":C" & x
    Next x
    Next y

    Set a = Application

    'get first "column"
    slice = a.Transpose(a.Index(arr, 0, 1))
    Debug.Print Join(slice, ", ")

    'get second "row" (note double transpose)
    slice = a.Transpose(a.Transpose(a.Index(arr, 2, 0)))
    Debug.Print Join(slice, ", ")

End Sub

Index() gives you a 2-d array - (x,1) or (1,x) - Transpose() will convert that to a 1-d array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.