Results 1 to 2 of 2

Macro: Copy text values of Visible cells (on a FILTERED data)

Threaded View

  1. #1
    Registered User
    Join Date
    06-05-2012
    Location
    Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    18

    Macro: Copy text values of Visible cells (on a FILTERED data)

    Hi all members,

    with this macro when i select several cells (using ctrl+click), for example cell F2 + G3 + H4 (then run the macro), it will will copy values of cell I2, I3, I4. In otherword, no matter on which column the cells you selected, it will always copy cell of column "I" (on that same row the cell was selected). and this macro will also automaticly remove any duplicates value.
    '''(macro originally from a guy call Karan and 1st modified by Alphafrog in this thread and 2nd modified by mike7952 in this thread)
    
    Sub CopySelectedCells()
     Dim str As String, rangeRow As Range
     With CreateObject("scripting.dictionary")
        For Each rangeRow In Selection.Rows
            If Trim$(Cells(rangeRow.Row, "I").Value) <> vbNullString Then
                If Not .Exists(Trim$(Cells(rangeRow.Row, "I").Value)) Then
                    .Item(Trim$(Cells(rangeRow.Row, "I").Value)) = Trim$(Cells(rangeRow.Row, "I").Value)
                End If
            End If
        Next
        str = Join$(.Items, ",")
     End With
        With New MSForms.DataObject
        .SetText str
        .PutInClipboard
    End With
    End Sub
    Now i have these 2 scenarios:

    scenario 1
    sheet contain AUTO FILTER
    if i select (USING CTRL + CLICK) cells F2, F4, F7, F9, F11
    then run macro
    it works OK. (copying ONLY values of cells I2, I4, I7, I9, I11 then removing any duplicates then put the copied values into clipboard which ready to be pasted into notepad or word etc)

    scenario 2 (THE PROBLEM)
    sheet contain AUTO FILTER
    if i select cells F2, F4, F7, F9, F11 (BY WAY OF CLICKING CELL F2, HOLD LEFT CLICK ON MOUSE AND DRAG DOWN UNTIL CELL F11)
    then run macro
    it DOESN'T work as it supposed. (it include copying the values of hidden cells (cells that are filtered in between) (i.e. cells I3,I5,I6,I8,I10)


    if someone can help modify the macro so that macro will copy only the visible cells as per scenario 2?
    Last edited by rampal; 01-24-2013 at 06:07 AM.

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