Condividi:        

problemi di formattazione celle tramite vb

Vuoi potenziare i tuoi documenti Word? Non sai come si fa una macro in Excel? Devi creare una presentazione in PowerPoint?
Oppure sei passato a OpenOffice e non sei sicuro di come lavorare al meglio?

Moderatori: Anthony47, Flash30005

problemi di formattazione celle tramite vb

Postdi piter123 » 06/12/07 14:26

salve, qualcuno mi spiega perchè questo codice formatta nel formato data solo la prima delle 4 colonne selezionate ?

Range("BB4:BB43").Select
Selection.NumberFormat = "dd/mm/yy;@"

Range("BK4:BK43").Select
Selection.NumberFormat = "dd/mm/yy;@"

Range("BT4:BT43").Select
Selection.NumberFormat = "dd/mm/yy;@"

Range("CC4:CC43").Select
Selection.NumberFormat = "dd/mm/yy;@"
piter123
Utente Senior
 
Post: 190
Iscritto il: 07/11/07 18:31

Sponsor
 

Postdi Anthony47 » 07/12/07 00:57

Una curiosita': ma che tipo di dati hai nelle colonne che non riesci a formattare? Ad esempio, se sono "stringhe" ben difficilmente il comando avra' un effetto.

Ciao, fai sapere.
Avatar utente
Anthony47
Moderatore
 
Post: 19213
Iscritto il: 21/03/06 16:03
Località: Ivrea

Postdi piter123 » 10/12/07 12:29

Intanto grazie, domani la provo e poi ti faccio sapere, anche se penso che mi hai dato la soluzione, grazie
piter123
Utente Senior
 
Post: 190
Iscritto il: 07/11/07 18:31

Postdi piter123 » 10/12/07 12:35

scusa ho sbagliato il topic, era l'altro quello relativo all'attivaione di formule nelle celle.

nel caso specifico le celle contengono date, ma ho lo stesso problema anche per la formattazione dei decimali di celle dove a volte ci sono numeri e in altre numeri convertiti in testo.
in questo ultimo esempio utilizzo la seguente riga ma non sempre funziona

Selection.NumberFormat = "0.00"
piter123
Utente Senior
 
Post: 190
Iscritto il: 07/11/07 18:31

Postdi piter123 » 10/12/07 12:36

per la precisione contengono date ottenute copme risultato della funzione cerca.verticale.

Grazie
piter123
Utente Senior
 
Post: 190
Iscritto il: 07/11/07 18:31

Postdi Anthony47 » 11/12/07 03:00

Sorry, non ho nessuna idea sul perche’ a volte va e a volte non va.
Per il formato data, mi dai un paio di esempi: che cosa c’ e’ all’ inizio nella cella (applicando il formato “numeri” con 2 decimali), che cosa vedi dopo aver applicato la formattazione, e che cosa ti aspettavi di vedere?

Idem per il problema con NumberFormat.

Ciao.
Avatar utente
Anthony47
Moderatore
 
Post: 19213
Iscritto il: 21/03/06 16:03
Località: Ivrea

Postdi piter123 » 11/12/07 08:09

ti posto il ralativo pezzo di codice (porta pazienza ma non sono un programmatore). la prima parte copia alcune celle in alte e poi tramite il comando "Selection.AutoFill Destination:=Range("BB4:BE43"), Type:=xlFillDefault" le trascina duplicandole creando delle colonne con formule.

Dopo di che esegue il codice di formattazione delle celle delle varie colonne relative alle date in formato data, ma formatta solo la prima e più precisamente la Range("BB4:BB43").Select, mentre le altre no, vedo il numero tipo 39876 relativo alla data.

Poi copia nelle textbox alcuni valori che servono per un'altra parte di codice.

poi fomatta alcune celle con i fari formati "Selection.NumberFormat "
ma quì succede una cosa analoga alla prima, il Range("O4:O43").Select
lo formatta bene senza decimali, ma il range Range("BF4:BF43").Select pur avendo impostato lo stesso tipo di formattazione e cioè Selection.NumberFormat = "0" mi fà vedere un decimale dopo la virgola.

Non ne vengo a capo, sò bne di sbagliare in qualcosa ma non essendo certo un esperto programmatore non sò come risolvere.

di seguito cè il codice, Grazie




'*** DAX SETT ***********************************************************
If CheckBox5.Value = True Then

'******* copia righe scad bid ask ctrl dde DAX SETT ****************
Range("BU152:BX152").Select
Selection.Copy
Range("BB4").Select
ActiveSheet.Paste
Selection.AutoFill Destination:=Range("BB4:BE43"), Type:=xlFillDefault
Range("BB4:BE43").Select
Range("I1").Select
Range("BU154:BX154").Select
Selection.Copy
Range("BK4").Select
ActiveSheet.Paste
Selection.AutoFill Destination:=Range("BK4:BN43"), Type:=xlFillDefault
Range("BK4:BN43").Select
Range("BU156:BX156").Select
Selection.Copy
Range("BT4").Select
ActiveSheet.Paste
Selection.AutoFill Destination:=Range("BT4:BW43"), Type:=xlFillDefault
Range("BT4:BW43").Select
Range("BU158:BX158").Select
Selection.Copy
Range("CC4").Select
ActiveSheet.Paste
Selection.AutoFill Destination:=Range("CC4:CF43"), Type:=xlFillDefault
Range("CC4:CF43").Select

' formatta le colonne data con formato data
Range("BB4:BB43").Select
Selection.NumberFormat = "dd/mm/yy;@"
Range("BK4:BK43").Select
Selection.NumberFormat = "dd/mm/yy;@"
Range("BT4:BT43").Select
Selection.NumberFormat = "dd/mm/yy;@"
Range("CC4:CC43").Select
Selection.NumberFormat = "dd/mm/yy;@"



' **** copia i valori sulle celle per i calcoli con il DAX SETT **************
Range("C8") = 5
Range("C10") = TextBox37.Text
Range("C12") = TextBox38.Text
Range("C14") = TextBox39.Text
If ComboBox1.Text = "Americana" Then
Range("C19") = "A"
End If
If ComboBox1.Text = "Europea" Then
Range("C19") = "E"
End If
Range("C21") = TextBox40.Text
Range("C23") = TextBox41.Text
Range("C25") = TextBox42.Text
Range("C27") = TextBox43.Text
Range("C29") = TextBox44.Text / 100
Range("C31") = TextBox45.Text / 100
If CheckBox10.Value = True Then
Range("C16") = 1
Else
Range("C16") = 0
End If
Range("B49") = TextBox77.Text

'*** sistema i campi con i decimali del DAX SETT ************************
Range("O4:O43").Select
Selection.NumberFormat = "0" 'LISTA STRIKE BOOK TEST
Range("BF4:BF43").Select
Selection.NumberFormat = "0" 'LISTA STRIKE DDE TEST
Range("CK64:CK103").Select
Selection.NumberFormat = "0" 'LISTA STRIKE PORGAIN TEST
Range("DD64:DD103").Select
Selection.NumberFormat = "0" 'LISTA STRIKE PORGAIN TEST
Range("DY64:DY103").Select
Selection.NumberFormat = "0" 'LISTA STRIKE GREGHE TEST
Range("EI64:EI103").Select
Selection.NumberFormat = "0" 'LISTA STRIKE GREGHE TEST
Range("AN4:AN43").Select
Selection.NumberFormat = "0" 'LISTA STRIKE BOOK PORT
Range("BX4:BX43").Select
Selection.NumberFormat = "0" 'LISTA STRIKE DDE PORT
Range("CK4:CK43").Select
Selection.NumberFormat = "0" 'LISTA STRIKE PORGAIN PORT
Range("DD4:DD43").Select
Selection.NumberFormat = "0" 'LISTA STRIKE PORGAIN PORT
Range("DY4:DY43").Select
Selection.NumberFormat = "0" 'LISTA STRIKE GRECHE PORT
Range("EI4:EI43").Select
Selection.NumberFormat = "0" 'LISTA STRIKE GRECHE PORT
Range("K4:L43").Select
Selection.NumberFormat = "0.0" 'LISTA PRICE BOOK TEST
Range("R4:S43").Select
Selection.NumberFormat = "0.0" 'LISTA PRICE BOOK TEST
Range("AJ4:AK43").Select
Selection.NumberFormat = "0.0" 'LISTA PRICE BOOK PORT
Range("AQ4:AR43").Select
Selection.NumberFormat = "0.0" 'LISTA PRICE BOOK PORT
Range("J47:L47").Select
Selection.NumberFormat = "0.0" 'LISTA PRICE SOTT TEST
Range("AQ47:AS47").Select
Selection.NumberFormat = "0.0" 'LISTA PRICE SOTT PORT
Range("AA30:AA31").Select
Selection.NumberFormat = "0.00" 'SOTT DDE E MANUALE
Range("X37:X38").Select
Selection.NumberFormat = "0" 'BREAKEVEN TEST
Range("X40").Select
Selection.NumberFormat = "0" 'MAX VALORE VOL DAY TEST
Range("AE37:AE38").Select
Selection.NumberFormat = "0" 'BREAKEVEN PORT
Range("AE40").Select
Selection.NumberFormat = "0" 'MAX VALORE VOL DAY PORT
Range("X46:X47").Select
Selection.NumberFormat = "0" 'ALLARMI SPOT
Range("BC4:DB43").Select
Selection.NumberFormat = "0.0" 'DDE ASK BID CALL TEST
Range("BL4:DM43").Select
Selection.NumberFormat = "0.0" 'DDE ASK BID PUT TEST
Range("BU4:DV43").Select
Selection.NumberFormat = "0.0" 'DDE ASK BID CALL TEST
Range("CD4:CE43").Select
Selection.NumberFormat = "0.0" 'DDE ASK BID PUT TEST
Range("CM64:CP103").Select
Selection.NumberFormat = "0.0" 'GAINPORT INGR BID ASK V.USCITA CALL TEST
Range("DF64:DI103").Select
Selection.NumberFormat = "0.0" 'GAINPORT INGR BID ASK V.USCITA PUT TEST
Range("CM4:CP43").Select
Selection.NumberFormat = "0.0" 'GAINPORT INGR BID ASK V.USCITA CALL PORT
Range("DF4:DI43").Select
Selection.NumberFormat = "0.0" 'GAINPORT INGR BID ASK V.USCITA PUT PORT
End If
'**********************************************************************
piter123
Utente Senior
 
Post: 190
Iscritto il: 07/11/07 18:31

Postdi Anthony47 » 11/12/07 19:33

Ho eseguito la tua macro, ed essa formatta le colonne BB, BK, BT e CC restituendomi la data in formato gg/mm/aa, avendo precedentemente inserito nelle celle di origine (BU15x) una data. Non so perche’ a te fa un altro effetto. Non avendo risposto alla domanda “che cosa c’ e’ all’ inizio nella cella (applicando il formato “numeri” con 2 decimali)” continuo a non avere la certezza che nella cella ci sia una “data” e a non scartare l’ ipotesi che la cella contenga una stringa.

La situazione per le celle numeriche e’ analoga, in quanto non so se i valori iniziali sono numerici o no; se sono indici che importi tramite dde e’ possibile che il formato dei dati in arrivo sia difforme da quello gestito dal tuo excel (es. separatore decimale, “punto” o “virgola”).
Ma se provi manualmente, riesci ad applicare la formattazione?

Inoltre ti segnalo questo post, dove spiegavo come si puo’ eseguire il debug di una macro:
http://www.pc-facile.com/forum/viewtopic.php?t=65537
Prova a inserire un breakpoint su una linea strategica (o piu’ linee) di codice e poi procedere passo-passo, controllando in parallelo l’ effetto sul foglio di lavoro.

Se risolvi, spiega l’ arcano; se NO, dicci qualcosa in piu' che potrebbe farci fare ulteriori ragionamenti.

Ciao.
Avatar utente
Anthony47
Moderatore
 
Post: 19213
Iscritto il: 21/03/06 16:03
Località: Ivrea

Postdi piter123 » 16/12/07 18:58

le formatazioni delle celle come prescritto in precedenza funzionano. Il fatto che non mi funzionavano è dovuto a un mio banalissimo e stupido errore.
il range di seguito sono stati copiati sbagliati esempio BC4:DB43 deve essere BC4:BD43, ho invertito BD con DB, così facendo andavo a riformattare anche le altre celle che dovevano avere altro tipo di formattazione. Il risultato finale era che non avevo le formattazioni aspettate e pensavo a quelche errore delle funzioni.

Di seguito riporto le righe sbagliate.

Grazie a tutti per l'attenzione e i suggerimenti



Range("BC4:DB43").Select
Selection.NumberFormat = "0.0" 'DDE ASK BID CALL TEST
Range("BL4:DM43").Select
Selection.NumberFormat = "0.0" 'DDE ASK BID PUT TEST
Range("BU4:DV43").Select
Selection.NumberFormat = "0.0" 'DDE ASK BID CALL TEST
piter123
Utente Senior
 
Post: 190
Iscritto il: 07/11/07 18:31

Postdi Anthony47 » 16/12/07 23:44

Grazie per averci aggiornati.
Hai familiarizzato con le procedure di debug, vero?

Ciao.
Avatar utente
Anthony47
Moderatore
 
Post: 19213
Iscritto il: 21/03/06 16:03
Località: Ivrea


Torna a Applicazioni Office Windows


Topic correlati a "problemi di formattazione celle tramite vb":


Chi c’è in linea

Visitano il forum: Nessuno e 19 ospiti