3

Just curious but is there any way to reduce this to smaller number of lines of code?

For k = 1 To 12
    Select Case k
        Case 1
            col = 9
        Case 2
            col = 10
        Case 3
            col = 11
        Case 4
            col = 12
        Case 5
            col = 13
        Case 6
            col = 14
        Case 7
            col = 15
        Case 8
            col = 16
        Case 9
            col = 17
        Case 10
            col = 18
        Case 11
            col = 19
        Case 12
            col = 20
    End Select
Next

Thanks!

1 Answer 1

3

How about:

For k = 1 to 12
   col = k + 8
Next

Or what you were probably looking for:

For k = 1 To 12
    Select Case k
        Case 1 To 12
            col = k + 8
    End Select
Next

Here's the relevant MSDN, you can scroll down for examples.

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

3 Comments

Sweeeet!! I knew they had to be a more better way of looping. thanks a lot
might want to add an else clause for safety
@PreetSangha Perhaps, but for this example it's really not needed. I considered it, but the OP wanted less lines and adding that would add no value in this circumstance.

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.