Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.visual-basic > #19626

VB6 Excel .NumberFormat

Path csiph.com!aioe.org!.POSTED.6QU6KY4WaR/cX1Ihan+B3w.user.gioia.aioe.org!not-for-mail
From "Sauro" <vicchi@crsscala.it>
Newsgroups it.comp.lang.visual-basic
Subject VB6 Excel .NumberFormat
Date Wed, 1 May 2019 15:57:25 +0200
Organization Aioe.org NNTP Server
Lines 47
Message-ID <qac8k5$b6n$1@gioia.aioe.org> (permalink)
NNTP-Posting-Host 6QU6KY4WaR/cX1Ihan+B3w.user.gioia.aioe.org
X-Complaints-To abuse@aioe.org
X-MSMail-Priority Normal
X-RFC2646 Format=Flowed; Original
X-Priority 3
X-Newsreader Microsoft Outlook Express 6.00.2900.5931
X-Notice Filtered by postfilter v. 0.9.2
X-MimeOLE Produced By Microsoft MimeOLE V6.00.2900.6157
Xref csiph.com it.comp.lang.visual-basic:19626

Show key headers only | View raw


Ciao a tutti

Ho dei codici come questi 0123ABCD e 01234567.
Se vado ad inserire il primo in un colonna excel, tutto bene.
Il secondo invece diventa subito 1234567 in quanto scompare lo 0 iniziale.

Bisogna dirgli che è un campo testo per poter conservare lo 0.
Una soluzione che avevo trovato era quella di anteporre
un apice:
.cells(r, c) = "'"  & Campo
Se è un xls di stampa o vsualizzazione può anche andare.
Ma se serve come strumento per trasferire dei dati da
un database ad un altro database diverso è brutto.
Costringe chi deve popolare il secondo database a
trattare i campi  per togliere l'apice.

Allora ho provato ad utilizzare la seguente sub:

Public Sub MettiPrimaColonnaTesto(Colonna As Long, _
    Optional RigaIn As Long = 1, _
    Optional RigaFin As Long = 5000)
Dim r As Long
With MyXL.Workbooks(1).Worksheets(1)
    For r = RigaIn To RigaFin
        .cells(r, Colonna).NumberFormat = "@"
    Next r
End With
End Sub

Funziona ma ci mette un sacco di tempo e poi
occorre sapere prima quanti record potrebbero
esserci come massimo.

Siccome conosco il tipo di campo che devo mettere
nelle singole celle ho deciso di faree così per ogni campo:

If TipoCampo = "Text" then
    .cells(r, c).NumberFormat = "@"
End If
.cells(r, c) = Campo(r)

Se pensate che ci sia qualcosa di meglio...

Grazie e saluti
Sauro 

Back to it.comp.lang.visual-basic | Previous | NextNext in thread | Find similar


Thread

VB6  Excel   .NumberFormat "Sauro" <vicchi@crsscala.it> - 2019-05-01 15:57 +0200
  Re: VB6  Excel   .NumberFormat "Freccia (VegetaSSj)" <NIENTESPAMfreccia_vegetassj@hotmail.invalid> - 2019-05-02 19:48 +0200
    Re: VB6  Excel   .NumberFormat "Sauro" <vicchi@crsscala.it> - 2019-05-05 19:33 +0200

csiph-web