Rinominare un foglio in base a valore data in una cella

Anonimo
2020-08-30T07:33:28+00:00

Salve.

In "Questa cartella di lavoro" ho il seguente codice:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    If Not Intersect(Target, Range("B12")) Is Nothing Then

        If Target <> "" And Target.Count = 1 Then

            ActiveSheet.Name = Target.Value

        End If

    End If

End Sub

Esso funziona. Nella Cella B12 a volte però ho una data e vorrei che il foglio venisse rinominato nel formato Mese anno (es. se la data è 01/04/2020 vorrei foglio rinominato Aprile 2020). 

Come posso modificare il codice?

Grazie a chi vorrà aiutarmi.

Giuseppe

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

Risposta accettata dall'autore della domanda

Anonimo
2020-08-30T13:33:17+00:00

Ciao Giuseppe,

Caro Norman,

Grazie. Era tempo che non ti sentivo. Spero tu stia in ottima forma!

Funziona. Grazie. E' possibile avere la prima lettera del mese in maiuscolo? (es. Agosto 2020)

Giuseppe

Prova questa versione del codice:

'========>>

Option Explicit

'-------->>

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    If Not Intersect(Target, Sh.Range("B12")) Is Nothing Then

        With Target

            If .Value <> "" And .Cells.Count = 1 Then

                If IsDate(.Value) Then

                    Sh.Name = Application.Proper(Format(.Value, "mmmm yy"))

                Else

                    Sh.Name = .Value

                End If

            End If

        End With

    End If

End Sub

'<<========

===

Regards,

Norman

La risposta è stata utile?

1 persona ha trovato utile questa risposta.
0 commenti Nessun commento

4 risposte aggiuntive

Ordina per: Più utili
  1. Anonimo
    2020-08-30T14:12:32+00:00

    Ciao Giuseppe,

    Perfetto.

    Grazie infinite Norman.

    Ti ringrazio per il cortese riscontro.

    Alla prossima.

    ===

    Reegards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2020-08-30T13:55:34+00:00

    Perfetto.

    Grazie infinite Norman.

    Giuseppe

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2020-08-30T13:06:39+00:00

    Caro Norman,

    Grazie. Era tempo che non ti sentivo. Spero tu stia in ottima forma!

    Funziona. Grazie. E' possibile avere la prima lettera del mese in maiuscolo? (es. Agosto 2020)

    Giuseppe

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2020-08-30T11:45:53+00:00

    Ciao Giuseppe,

    In "Questa cartella di lavoro" ho il seguente codice:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

        If Not Intersect(Target, Range("B12")) Is Nothing Then

            If Target <> "" And Target.Count = 1 Then

                ActiveSheet.Name = Target.Value

            End If

        End If

    End Sub

    Esso funziona. Nella Cella B12 a volte però ho una data e vorrei che il foglio venisse rinominato nel formato Mese anno (es. se la data è 01/04/2020 vorrei foglio rinominato Aprile 2020). 

    Come posso modificare il codice?

    Prova qualcosa del genere:

    '========>>

    Option Explicit

    '-------->>

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

        If Not Intersect(Target, Sh.Range("B12")) Is Nothing Then

            With Target

                If .Value <> "" And .Cells.Count = 1 Then

                    If IsDate(.Value) Then

                        Sh.Name = Format(.Value, "mmmm yy")

                    Else

                        Sh.Name = .Value

                    End If

                End If

            End With

        End If

    End Sub

    '<<========

    ===

    Regards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento