Il baco e l’elefante

Come saprai, in la data è un numero seriale positivo dove 1 è il primo di gennaio del 1900. Oggi, 15 marzo 2023, corrisponde al numero 45000.

In Excel c’è un baco: l’anno 1900 è trattato come bisestile, per cui il 29/02/1900, che non è esistito, viene riconosciuto come data e corrisponde al numero 60.

Come si vede in questa tabella, le date anteriori al 01/01/1900 non vengono riconosciute come data e vengono gestite come testo: invece il 29/02/1900 viene riconosciuto (la formula nella colonna B è =A2 con formato numero senza decimali):

I fogli di Google invece, gestiscono correttamente il 1900 come anno non bisestile, e sono anche capaci di utilizzale le date anteriori al primo gennaio del 1900.

Ma non possono permettersi di dichiarare che oggi è il numero 45001, diventando così incompatibili con Excel.

Quindi cosa si sono inventati: per Google il numero 1 corrisponde al 31/12/1899 invece che al 01/01/1900, la numerazione rimane sfalsata fino al 28/02/1900, e comincia a corrispondere dal primo di marzo 1900 in poi:

Conversazione con ChatGPT

In Excel, I have a column of IP addresses that sometimes are recognized as text and sometimes as number. In another column I have written a formula that will convert the IP address as text in 4 groups of 3 digits, separated by a fullstop. The formula is quite complex and I wonder if a simpler version is possible. Here it is:

=IF(ISNUMBER(A2);RIGHT(“00″&LEFT(A2;LEN(A2)-9);3)&”.”&MID(A2;LEN(A2)-8;3)&”.”&MID(A2;LEN(A2)-5;3)&”.”&RIGHT(A2;3);RIGHT(“00″&LEFT(A2;FIND(“.”;A2)-1);3)&”.”&RIGHT(“00″&MID(A2;FIND(“.”;A2)+1;FIND(“.”;A2;(FIND(“.”;A2))+1)-FIND(“.”;A2)-1);3)&”.”&RIGHT(“00″&MID($A2;FIND(“.”;A2;(FIND(“.”;A2))+1)+1;FIND(“.”;A2;FIND(“.”;A2;(FIND(“.”;A2))+1)+1)-FIND(“.”;A2;(FIND(“.”;A2))+1)-1);3)&”.”&RIGHT(“00″&MID(A2;FIND(“.”;A2;FIND(“.”;A2;(FIND(“.”;A2))+1)+1)+1;LEN(A2)-FIND(“.”;A2;FIND(“.”;A2;(FIND(“.”;A2))+1)+1));3))

Yes, a simpler version of the formula is possible. Here’s an alternative:

 =TEXT(A2,”000.000.000.000″)

 This formula converts the value in cell A2 to text using the format “000.000.000.000”, which separates the IP address into 4 groups of 3 digits separated by fullstops.

Thanks, but your formula only works when the IP address is recognized as a number, like in 147.161.232.179. It does not work when the number is recognized as text, like 147.161.232.1

You’re correct, my previous formula will only work if the IP address is recognized as a number. Here’s a modified version of the formula that works for both text and number formatted IP addresses:

 =IF(ISNUMBER(A2),TEXT(A2,”000.000.000.000″),SUBSTITUTE(A2,”.”,”.00″,3)&”.00″)

 This formula checks if the value in cell A2 is recognized as a number, and if so, converts it to text using the format “000.000.000.000”. If it’s recognized as text, the formula uses the SUBSTITUTE function to replace the third instance of “.” with “.00”. This ensures that all IP addresses are formatted as 4 groups of 3 digits separated by fullstops, regardless of their original format.

Good, but IP addresses are recognized as text when any of the second, third or fourh group contains one or two digits. Your formula only works if the fourth group contains precisely one digit

You’re correct, my previous formula does not handle IP addresses where any of the second, third, or fourth groups contain one or two digits. Here’s a modified version of the formula that works for all IP addresses:

 =TEXTJOIN(“.”,TRUE,IF(LEN(A2)<=12,LEFT(A2,3),LEFT(A2,FIND(“.”,A2)-1)),MID(A2,FIND(“.”,A2)+1,3),MID(A2,FIND(“.”,A2,FIND(“.”,A2)+1)+1,3),IF(LEN(A2)<=12,RIGHT(A2,3),RIGHT(A2,LEN(A2)-FIND(“.”,A2,FIND(“.”,A2,FIND(“.”,A2)+1)+1))))

This formula uses the LEN function to determine the length of the IP address, and the FIND function to locate the position of the “.” characters. It uses the LEFT and RIGHT functions to extract the first and last groups of the IP address, and the MID function to extract the second and third groups. Finally, it uses the TEXTJOIN function to concatenate the groups with “.” as the separator. This formula can handle IP addresses with one or two digits in any of the second, third, or fourth groups.

Good, so now we can put together this formula with the one in case the IP address is recognized as a number

Yes, here’s a combined formula that handles both text and number formatted IP addresses:

 =IF(ISNUMBER(A2),TEXT(A2,”000.000.000.000″),TEXTJOIN(“.”,TRUE,IF(LEN(A2)<=12,LEFT(A2,3),LEFT(A2,FIND(“.”,A2)-1)),MID(A2,FIND(“.”,A2)+1,3),MID(A2,FIND(“.”,A2,FIND(“.”,A2)+1)+1,3),IF(LEN(A2)<=12,RIGHT(A2,3),RIGHT(A2,LEN(A2)-FIND(“.”,A2,FIND(“.”,A2,FIND(“.”,A2)+1)+1)))))

This formula first checks if the value in cell A2 is recognized as a number, and if so, converts it to text using the format “000.000.000.000”. If it’s recognized as text, it uses the TEXTJOIN function to format the IP address as described in my previous answer. This formula can handle both text and number formatted IP addresses, regardless of the number of digits in each group.

Can you translate the formula for the Italian version of Excel? Keep in mind that you need to separate the arguments with a semicolon

Yes, here’s the equivalent formula for the Italian version of Excel, where the arguments are separated with a semicolon:

=SE(ÈNUMERO(A2);TESTO(A2;”000.000.000.000″);UNISCI.TESTO(“.”,VERO,SE(LUNGHEZZA(A2)<=12;SINISTRA(A2;3);SINISTRA(A2;TROVA(“.”;A2)-1));MEDIO(A2;TROVA(“.”;A2)+1;3);MEDIO(A2;TROVA(“.”;A2;TROVA(“.”;A2)+1)+1;3);SE(LUNGHEZZA(A2)<=12;DESTRA(A2;3);DESTRA(A2;LUNGHEZZA(A2)-TROVA(“.”;A2;TROVA(“.”;A2;TROVA(“.”;A2)+1)+1)))))

This formula uses the same logic as the original formula, but with the equivalent functions for the Italian version of Excel. The functions used include:

SE (IF)

ÈNUMERO (ISNUMBER)

TESTO (TEXT)

UNISCI.TESTO (TEXTJOIN)

LUNGHEZZA (LEN)

TROVA (FIND)

SINISTRA (LEFT)

DESTRA (RIGHT)

MEDIO (MID)

Excel pangram finder

C’è un simpatico giochino del New York Times, Spelling Bee, dove ti danno sette caratteri, di cui uno obbligatorio, con i quali devi cercare di comporre più parole e fare più punti possibili, con il seguente criterio:

  • Le parole devono avere almeno 4 caratteri.
  • Le parole di 4 caratteri prendono un solo punto.
  • Le parole con più di 4 caratteri prendono un punto per ogni carattere.
  • Le parole che usano tutti i 7 caratteri (pangram!) prendono un ulteriore bonus di 7 punti.

Il giochino mi ha dato la spunta per utilizzare una delle funzionalità più antiche e meno conosciute di Excel: il filtro avanzato.

spelling bee pangram finder

Condivido quindi il file spelling bee pangram finder che utilizza il filtro avanzato in modalità AND per estrarre i possibili pangram da un elenco di circa 75.000 parole inglesi composte da 7 caratteri.

Come consiglio di fare sempre, ho aggiunto un foglio Note con le spiegazioni del caso. Ti prego di leggerlo prima di mettere mano al file.

Tutto bene quel che finisce bene

Primo dramma:

Lunedì scorso avevo un corso di Excel in centro a Milano alle nove. Dato che era la prima volta che visitavo il cliente, volevo arrivare con buon anticipo e ho preso il treno di conseguenza. Arrivato a Milano Cadorna sono sceso in metro e ho trovato le carrozze ferme una folla immensa ad aspettare. Dopo qualche minuto, l’annuncio di “linea interrotta, seguiranno comunicazioni”. Che fare? Ho avvertito del ritardo e mi sono avviato a piedi. Sono arrivato (puf pant) alle nove e venti. Odio arrivare in ritardo. Detesto chi arriva in ritardo.

Secondo dramma:

Entro nella sala riunioni predisposta per la lezione, entrano gli allievi e si siedono attorno al tavolo, tirano fuori i carta e penna, ma non hanno i computer! Rimango sorpreso e chiedo spiegazioni: “e i computer?”. Rimangono sorpresi e chiedono “ah, ma ci vogliono?” (purtroppo non avevano letto le istruzioni). Mantengo la calma e spiego che per imparare bisogna fare (doh!), che il corso è in realtà un laboratorio, e senza PC è inutile. Invece di raffazzonare qualcosa al volo, decido di rimandare il tutto di una settimana.

Già che c’ero, mi son detto “conosciamoci meglio” e mi sono fatto raccontare come usano Excel, che tipo di problemi hanno, e ho fatto vedere alcuni strumenti che potrebbero essere loro utili, promettendo che ci avremmo lavorato durante il corso.

Finale a sorpresa:

Insomma, ho buttato la mattina per niente, dove niente è la mia retribuzione. Ma il cliente è rimasto molto contento, e vuole che tenga lo stesso corso per tutti i membri della sua associazione.

Morale della storia:

Sento dire spesso, e Amazon insegna, che “l’assistenza clienti è il nuovo marketing”. Ebbene, è vero.

Trasformare una data estesa inglese in data di Excel Italiano

In un foglio di Excel ho inserito una query a una pagina web inglese. Una delle colonne si chiama Last report e contiene una data/ora in inglese, scritta così:
12 January 2020 11.00.

A causa del mese in inglese e del punto separatore tra ora e minuti, Excel riconosce la stringa come testo. A me invece serve come data di Excel, ovvero così:
12/01/2020 10:00.

Per prima cosa, in un nuovo foglio ho inerito i mesi inglesi nella colonna A e un numero progressivo da 1 a 12 nella colonna B. Ho dato il nome mesi all’intervallo A1:B:12.

Per ricostruire la data ho usato prima di tutto la funzione =SE.ERRORE(), perché “Last report” può anche essere vuota; al suo interno ho inserito la funzione DATA(ANNO;MESE;GIORNO) a cui ho sommato le ore facendo attenzione a quanto segue:

  • I nomi dei mesi hanno lunghezze diverse, per cui STRINGA.ESTRAI() da solo non basta
  • I minuti sono sempre a zero
  • Le formule di testo restituiscono testo, ma per sommare l’ora alla data ho bisogno dell’ora come numero; inoltre il numero che mi serve non è l’intero ma il suo ventiquattresimo (per Excel un giorno vale 1 e un’ora vale 1/24)
  • La cella risultato usa la formattazione personalizzata
    gg/mm/aaaa hh:mm

Per ottenere l’ANNO:
SINISTRA(DESTRA([@[Last Report]];10);4)

Per ottenere il MESE:
CERCA.VERT(STRINGA.ESTRAI([@[Last Report]];4;LUNGHEZZA([@[Last Report]])-14);mesi;2;0)

Per ottenere il GIORNO:
SINISTRA([@[Last Report]];2)

Per ottenere le ORE:
NUMERO.VALORE(SINISTRA(DESTRA([@[Last Report]];5);2))/24

La formula finale è questa:
=SE.ERRORE(DATA(SINISTRA(DESTRA([@[Last Report]];10);4);CERCA.VERT(STRINGA.ESTRAI([@[Last Report]];4;LUNGHEZZA([@[Last Report]])-14);mesi;2;0);SINISTRA([@[Last Report]];2))+NUMERO.VALORE(SINISTRA(DESTRA([@[Last Report]];5);2))/24;”-“)