0

I have an excel file with 430 columns and I need to loop through columns 28-32 39-56 60-71 89-268 276-291 323-396 416-418 420-429

For that purpose, I am creating an array, but I don't how I can assign all values between each bounds. The array should contain the values 28, 29, 30, 31, 32, 39, 40,... and so on.

I've been looking, but I might not be using the correct keywords.

4
  • What do you mean by assigning the array values between each bounds? You received a (clever) answer showing how to treat the bounds part. It would be good if you better explain what the mentioned assigning process does mean. The bounds do not have the same number of columns. Should the code assign the array on each such column belonging to the mentioned bounds? If not, please better explain what you want accomplishing. The array you show us does not contain something to be associated to above bounds definition... Commented Dec 28, 2021 at 17:13
  • If you assign these column numbers to an array, as you indicated, you shouldn't need to know the bounds of the different column ranges. Each column number will be stored in an array element and the element indexes will be sequential from 0 to n (assuming default Option Base 0). So you would loop through each array element, each of which is one of your column numbers. Commented Dec 28, 2021 at 17:26
  • @FaneDuru i meant the bounds between each interval, the left- and right bounds. The array I show contains the values in the first interval, the 2nd interval, and so on. It seems "bounds" means something else in VBA ? Commented Dec 28, 2021 at 17:40
  • @bugdrown one of the goals was not to write each element of these intervals, too time consuming Commented Dec 28, 2021 at 17:45

1 Answer 1

4

Rather than using an array, one alternative might be to use Select Case, something like this:

Sub tester()
    Dim col As Range
    For Each col In ActiveSheet.Range("AB:PM").Columns
        Select Case col.Column
            Case 28 To 32, 39 To 56, 60 To 71 ' and so on
                ' Process col here       
        End Select
    Next
End Sub
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.