+ Reply to Thread
Results 1 to 3 of 3

How to iterate over columns in a range

  1. #1
    Registered User
    Join Date
    01-04-2005
    Posts
    7

    Question How to iterate over columns in a range

    I would like to do something like this: I want to iterate over the selected rows in the active worksheet and for each row, iterate or access the cells in that row.

    Dim myRange As Range
    Dim wksSheet As Worksheet
    Dim A$

    Set myRange = Selection
    For Each r In myRange
    A$ = ""

    A$ = ActiveSheet.Cells(r, 1) <---DOES NOT WORK
    A$ = A$ + ", " + ActiveSheet.Cells(r, 2)
    A$ = A$ + ", " + ActiveSheet.Cells(r, 3)
    MsgBox A$
    Next r
    End Sub

    Thanks.

    RON

  2. #2
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451

    How to iterate over columns

    Try this macro

    Sub macro()
    Dim myRange As Range
    Dim wksSheet As Worksheet
    Dim A$

    Set myRange = Selection
    For Each r In myRange.Rows
    A$ = ""

    A$ = ActiveSheet.Cells(r.Row, 1)
    A$ = A$ + ", " + ActiveSheet.Cells(r.Row, 2)
    A$ = A$ + ", " + ActiveSheet.Cells(r.Row, 3)
    MsgBox A$
    Next r
    End Sub

  3. #3
    Registered User
    Join Date
    01-04-2005
    Posts
    7
    That worked!! Thanks.

    RON

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1