+ Reply to Thread
Results 1 to 21 of 21

"Ambiguous name detected: FormatCell"

Hybrid View

  1. #1
    Registered User
    Join Date
    08-31-2009
    Location
    washington, dc
    MS-Off Ver
    Excel 2003
    Posts
    55

    "Ambiguous name detected: FormatCell"

    Hello,

    I need my macros to search for the word "Cancel" in columns "T". Once found, I need the macros to make that entire row a certain pattern ( .Pattern = xlGray16)

    There will be other wording in these cells that contain "Cancel" or "Cancelled".

    A compile error keeps occurring. It says "Ambiguous name detected: FormatCell"..

    I'm confused with it..... any suggestions?

    
    Sub DoCancelCells()
    
        Dim strSearchString As String
        Dim wksSheet As Worksheet
        Dim rngSearchRange As Range
        Dim intSearchCount As Integer
       
        Application.ScreenUpdating = False
       
        'String to search for.
        strSearchString = "cancel"
        intSearchCount = 0
       
        For Each wksSheet In ActiveWorkbook.Sheets
       
        wksSheet.Select
       
            Set rngSearchRange = Range("T1:T" & Range("T" & Rows.Count).End(xlUp).Row)
           
                For Each cell In rngSearchRange
               
                    If cell.Value = strSearchString Then
                   
                        intSearchCount = intSearchCount + 1
                       
                        Call FormatCell(cell.Address)
                   
                    End If
                   
                Next cell
               
                Set rngSearchRange = Nothing
       
        Next wksSheet
       
       
        Application.ScreenUpdating = True
       
    End Sub
    Sub FormatCell(strCellAddress As String)
    
        With Range(strCellAddress).EntireRow.Interior
            .Pattern = xlGray16
            .PatternColorIndex = xlAutomatic
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    Thank you in advance for your help.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    re: "Ambiguous name detected: FormatCell"

    You have two copies of the sub in the module. Delete one.

    Or replace all the code with this:
    Sub DoCancelCells()
        Const sWhat     As String = "cancel"
        Dim rFind       As Range
        Dim sAdr        As String
        Dim wks         As Worksheet
    
        For Each wks In ActiveWorkbook.Worksheets
            With wks.Range("T1:T" & wks.Range("T" & Rows.Count).End(xlUp).Row)
                Set rFind = .Find(What:=sWhat, _
                                  LookIn:=xlValues, LookAt:=xlWhole, _
                                  MatchCase:=False, MatchByte:=False)
                If Not rFind Is Nothing Then
                    sAdr = rFind.Address
                    Do
                        FormatCell rFind
                        Set rFind = .FindNext(rFind)
                    Loop Until rFind.Address = sAdr
                End If
            End With
        Next wks
    End Sub
    
    Sub FormatCell(r As Range)
        With r.EntireRow.Interior
            .Pattern = xlGray16
            .PatternColorIndex = xlAutomatic
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    08-31-2009
    Location
    washington, dc
    MS-Off Ver
    Excel 2003
    Posts
    55

    re: "Ambiguous name detected: FormatCell"

    Thanks for the same reply. I received the exact same error message.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    re: "Ambiguous name detected: FormatCell"

    Search for FormatCell project-wide. There are two (or more) copies. Delete all but one.

  5. #5
    Registered User
    Join Date
    08-31-2009
    Location
    washington, dc
    MS-Off Ver
    Excel 2003
    Posts
    55

    re: "Ambiguous name detected: FormatCell"

    those were the only two in the project i just Control + F 'd

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    re: "Ambiguous name detected: FormatCell"

    Post the workbook. You can delete all the data.

+ 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