Excel Forum Per condividere esperienze su Microsoft Excel

VBA sui "NOMI" celle

  • Messaggi
  • ABCDEF@Excel
    00 31/10/2020 03:33
    Ciao a tutti,
    non riesco prendere il nome del foglio e l'indirizzo delle celle con "NOME". Dove sbaglio?
    Grazie mille
  • OFFLINE
    federico460
    Post: 1.983
    Registrato il: 10/10/2013
    Città: VICENZA
    Età: 69
    Utente Veteran
    365
    00 31/10/2020 09:03
    ciao
    non penso sia quello che vuoi
    ma ci provo

    Sub A()
    Dim wk As Workbook
    Dim n As Name, rg, f
    f = "Foglio1"
    Set wk = ThisWorkbook
    Range("A1:D4") = ""
    With wk
    For Each n In .Names
    rg = rg + 1
    Cells(rg, 1) = n.Name
    Cells(rg, 2) = .Names(n.Name)
    'MsgBox .Names(n.Name).RefersTo
    'MsgBox .Names(n.Name)
    'If InStr(n.RefersTo, "#REF") Then n.delete
    If ActiveSheet.Name = f Then Cells(rg, 3) = ActiveSheet.Name
    If ActiveSheet.Name = f Then Cells(rg, 4) = Right(Cells(rg, 2), Len(Cells(rg, 2)) - Len(Cells(rg, 3)) - 2)
    Next
    End With
    End Sub

  • OFFLINE
    by sal
    Post: 6.130
    Registrato il: 14/11/2004
    Utente Master
    Office 2019
    00 31/10/2020 11:00
    Ciao Prova cosi. se ho capito bene

    Sub A()
    Dim wk As Workbook
    Dim n As Name, rg, f
    f = "Foglio1"
    Set wk = ThisWorkbook
    Range("A1:B4") = ""
    With wk
        For Each n In .Names
            rg = rg + 1
            Cells(rg, 1) = n.Name
            Cells(rg, 2) = .Names(n.Name)
            'MsgBox .Names(n.Name).RefersTo
            'MsgBox .Names(n.Name)
            'If InStr(n.RefersTo, "#REF") Then n.delete
            If Mid(.Names(n.Name), 2, InStr(.Names(n.Name), "!") - 2) = f Then Cells(rg, 3) = Mid(.Names(n.Name), 2, InStr(.Names(n.Name), "!") - 2)
            If Mid(.Names(n.Name), 2, InStr(.Names(n.Name), "!") - 2) = f Then Cells(rg, 4) = Mid(.Names(n.Name), 10)
        Next
    End With
    End Sub


    Ciao By sal (8-D
    se ti piace la soluzione sostienici con una DONAZIONE a piacere. Grazie clicca qui
  • ABCDEF@Excel
    00 31/10/2020 11:19
    @federico460
    Grazie. Mi riferivo hai NOMI delle celle, mi ero dimenticato di mettere il segno =
    f = "=Foglio1"

    @By sal
    Grazie meglio il Tuo. Mi chiedevo del "perchè" e ho notato che parti dal 2° carattere
    If Mid(.Names(n.Name), 1, InStr(.Names(n.Name), "!") - 1) = f Then Cells(rg, 3) = Mid(.Names(n.Name), 2, InStr(.Names(n.Name), "!") - 2)
    If Mid(.Names(n.Name), 1, InStr(.Names(n.Name), "!") - 1) = f Then Cells(rg, 4) = Mid(.Names(n.Name), InStr(.Names(n.Name), "!") + 1, 10)

    [Modificato da ABCDEF@Excel 31/10/2020 11:22]