È soltanto un Pokémon con le armi o è un qualcosa di più? Vieni a parlarne su Award & Oscar!

Excel Forum Per condividere esperienze su Microsoft Excel

Cerca con Macro

  • Messaggi
  • OFFLINE
    gionox
    Post: 144
    Registrato il: 12/04/2013
    Città: BARI
    Età: 34
    Utente Junior
    2016
    00 13/07/2017 17:06
    Ciao ragazzi, mi servirebbe una macro per cercare se i valori contenuti nelle celle delle colonne D ed E sono presenti nella colonna A.
    Qualsiasi tipo di segnalazione va bene, anche un semplice sfondo giallo sul valore.
    Grazie.

    P.S: non ho caricato nessun file esempio solo perchè credo che sia intuibile già cosi la richiesta, caso contrario ve lo carico.

    Grazie :)
  • OFFLINE
    dodo47
    Post: 1.469
    Registrato il: 06/04/2013
    Utente Veteran
    2010
    00 13/07/2017 17:30
    Ciao
    ma devi cercare in colonna A tutti i valori presenti nelle celle in D ed E oppure uno per volta?

    E poi una volta evidenziato i/il valori/e cercato deve toglire l'evidenziazione per le successive richieste?..altrimenti alla fine la colonna A sarà tutta una evidenziazione.

    saluti

    [Modificato da dodo47 13/07/2017 17:30]
    Domenico
    Win 10 - Excel 2016
  • OFFLINE
    gionox
    Post: 144
    Registrato il: 12/04/2013
    Città: BARI
    Età: 34
    Utente Junior
    2016
    00 13/07/2017 18:16
    Praticamente D ed E sono due colonne in cui ho valori, diversi. Questi potrebbero essere presenti in A. Se si, basta che si evidenzi la cella. Anche se diventa tutto giallo :=)
  • OFFLINE
    dodo47
    Post: 1.471
    Registrato il: 06/04/2013
    Utente Veteran
    2010
    00 13/07/2017 19:01
    Ciao
    ...contento tu....
    saluti

    Sub xx()
    Dim ToFind As Range, wFind As Range, cel As Range, rToFind As Long
    Dim rD As Long, rE As Long, c As Object, firstAddress As String
    rD = Range("D" & Rows.Count).End(xlUp).Row
    rE = Range("E" & Rows.Count).End(xlUp).Row
    If rD >= rE Then rToFind = rD Else rToFind = rE
    
    Set ToFind = Range("D1:E" & rToFind)
    Set wFind = Range("A:A")
    
    For Each cel In ToFind
        If Not IsEmpty(cel.Value) Then
            With wFind
                Set c = .Find(cel.Value, LookIn:=xlValues, lookat:=xlWhole)
                If Not c Is Nothing Then
                    firstAddress = c.Address
                    Do
                        Range(c.Address).Interior.ColorIndex = 4
                        Set c = .FindNext(c)
                    Loop While Not c Is Nothing And c.Address <> firstAddress
                End If
            End With
        End If
    Next cel
    Set ToFind = Nothing
    Set wFind = Nothing
    Set c = Nothing
    End Sub


    Domenico
    Win 10 - Excel 2016
  • OFFLINE
    gionox
    Post: 145
    Registrato il: 12/04/2013
    Città: BARI
    Età: 34
    Utente Junior
    2016
    00 13/07/2017 19:09
    Graziee :)