Results 1 to 2 of 2

To apply the macro only on the visible cell (filtered data alone)

Threaded View

  1. #1
    Registered User
    Join Date
    09-13-2021
    Location
    India
    MS-Off Ver
    365
    Posts
    36

    To apply the macro only on the visible cell (filtered data alone)

    Hello everyone,

    I got the below code from this forum only, unable to post the link. Due to the warning message "You are not allowed to post any kinds of links, images or videos until you post a few times."

    Public Sub HighlightFirstOccurrence()
    
    Dim d As Object
    Dim x As Long
    Dim y As Long
    Dim z As Long
    Dim s As String
    Dim words As Variant
    Dim c As Long
    
    
    For y = 11 To 15000
        For x = 4 To 4
            s = Cells(y, x).Value
            If Trim(s) <> "" Then
                words = Split(s, " ")
                c = 1
                For z = 0 To UBound(words)
                    If Not d.Exists(words(z)) Then
                        d.Add words(z), words(z)
                        Cells(y, x).Characters(Start:=c, Length:=Len(words(z))).Font.Color = RGB(255, 0, 0)
                    End If
                   
                    c = c + Len(words(z)) + 1
                Next z
                 
            End If
        Next x
    Next y
    
    End Sub

    The above macro highlights the first occurrence of the word in red font (in column D alone). (Data is found in column D11 to E15000. Range D10 & E10 contains the header). Currently the macro takes the whole data set while highlighting, even when the filter is on and only 15 rows are visible.

    Is it possible to find last row of visible cells alone (minus the header) and incorporate into the code. I want the macro to take only the visible cells into consideration while highlighting for first occurrence word. Can anybody please help ?. When i tried to include "SpecialCells(xlCellTypeVisible)", I am always getting an error. "Run time error 13, type mismatch. Please help.
    Attached Files Attached Files
    Last edited by Lona; 09-24-2021 at 04:09 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Apply cell numbering to visible rows only
    By Groovicles in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-24-2017, 11:44 AM
  2. [SOLVED] Apply Macro to Filtered List
    By YOO629 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-03-2015, 05:10 PM
  3. Offset to next visible cell in filtered data
    By Varun13 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2013, 04:37 AM
  4. [SOLVED] Macro to select visible rows containg data in filtered list
    By knevil in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-15-2013, 01:22 PM
  5. [SOLVED] Macro: Copy text values of Visible cells (on a FILTERED data)
    By rampal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 06:12 AM
  6. Error checking of visible filtered data - Display text in textbox if no data visible
    By cocobean in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2012, 12:58 AM
  7. Macro to select till last cell visible(numbers in cells) (filtered) ignoring formulas
    By DiegoBoffa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2012, 11:10 PM

Tags for this Thread

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