Consulting

Results 1 to 3 of 3

Thread: Solved: For Each Loop- Multiple columns?

  1. #1

    Solved: For Each Loop- Multiple columns?

    In this line of code, it targets column "D" or 4, can I specifiy another non-adjacent column in the same line w/out having to repeat the entire code for another column?
    For Each c In Intersect(Ws.Columns(4), Ws.UsedRange)

    ie.
    For Each c In Intersect(Ws.Columns(4) & (23), Ws.UsedRange)

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    IMO using the range object in conjunction with the column letter(s) is easier and should get you what you want, e.g.[VBA]For Each c In Application.Intersect(Ws.Range("D, W:W"), Ws.UsedRange)[/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Thanks Johnske

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •