Excel - COMO APLICO DE NUMEROS A LETRAS EN UN FORMULARIO VBA DE EXCEL

 
Vista:

COMO APLICO DE NUMEROS A LETRAS EN UN FORMULARIO VBA DE EXCEL

Publicado por JORGE PALACIOS (9 intervenciones) el 07/07/2012 09:42:38
Buenas Noches, estoy haciendo un programa de facturación, tengo un formulario factura por el cual alimento datos para imprimir una factura.
lo que necesito es que en un textbox (txtLetras) me convierta números en letras provenientes de otro textbox (txtTotal)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Gonzalo Quintana
Val: 13
Ha disminuido su posición en 50 puestos en Excel (en relación al último mes)
Gráfica de Excel

COMO APLICO DE NUMEROS A LETRAS EN UN FORMULARIO VBA DE EXCEL

Publicado por Gonzalo Quintana (73 intervenciones) el 10/07/2012 19:02:53
Jorge Palacios
Buenas tardes, desde donde te escribo...
Que tipo de numeración es la que tiene txtTotal?? Se debería reemplazar una letra por cada número??
Favor aclarar...
Saludos,

Gonzalo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

COMO APLICO DE NUMEROS A LETRAS EN UN FORMULARIO VBA DE EXCEL

Publicado por JORGE PALACIOS (9 intervenciones) el 10/07/2012 19:53:06
Saludos, la numeracion no se a que te refieres.
numeracion pesos- colombianos
numeracion es el total de una factura = subtotal + iva + flete = total
total es el que necesito representar en letras en un formulario vba en una casilla textbox

la formula para hacerlo en excel la he visto. pero quiero hacerlo directamente en vba de excel
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Gonzalo Quintana
Val: 13
Ha disminuido su posición en 50 puestos en Excel (en relación al último mes)
Gráfica de Excel

COMO APLICO DE NUMEROS A LETRAS EN UN FORMULARIO VBA DE EXCEL

Publicado por Gonzalo Quintana (73 intervenciones) el 10/07/2012 20:21:48
Jorge
Ahora entiendo a lo que te referías...
Buscando por la web, encontré el siguiente código que transforma de números a letras, aunque hay que adaptarlo bastante:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
Option Explicit
 
 
     '********************************************************
      ' Adaptado de Microsoft - JLD Excel Blog en Castellano *
      '*******************************************************
     '****************
      ' Main Function *
      '****************
 
      Function SpellNumber2(ByVal MyNumber, Sep, Mon)
          Dim Dollars, Cents, Temp
          Dim DecimalPlace, Count
          Dim origNumLen, origNum
 
          ReDim place(9) As String
          place(2) = " Mil "
          place(3) = " Millones "
          place(4) = " Billones "
          place(5) = " Trillones "
 
          ' String representation of amount.
          MyNumber = Trim(CStr(MyNumber))
          origNumLen = Len(MyNumber)
          origNum = MyNumber
 
          ' Position of decimal place 0 if none.
          If Sep = "." Then DecimalPlace = InStr(MyNumber, ".")
          If Sep = "," Then DecimalPlace = InStr(MyNumber, ",")
 
          ' Convert cents and set MyNumber to currency amount.
          If DecimalPlace > 0 Then
              Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
              MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
          End If
 
          Count = 1
          Do While MyNumber <> ""
              Temp = GetHundreds(Right(MyNumber, 3))
              If Temp <> "" Then
                If Temp = "UN" And Count > 2 Then
                        Dollars = Temp & Left(place(Count), Len(place(Count)) - 3) _
                            & " " & Dollars
                Else
                        Dollars = Temp & place(Count) & Dollars
                End If
            End If
              If Len(MyNumber) > 3 Then
                  MyNumber = Left(MyNumber, Len(MyNumber) - 3)
              Else
                  MyNumber = ""
              End If
              Count = Count + 1
          Loop
 
          Select Case Dollars
              Case ""
                  Dollars = "Cero " & Mon
              Case "UN"
                  Dollars = "Un " & Left(Mon, Len(Mon) - 1)
              Case Else
                  If origNumLen > 6 And (origNum Mod 1000000) = 0 Then
                    Dollars = Dollars & " " & "de " & Mon
                  Else
                    Dollars = Dollars & " " & Mon
                  End If
          End Select
 
          Select Case Cents
              Case ""
                  Cents = " con cero centavos"
              Case "One"
                  Cents = " con un centavo"
              Case Else
                  Cents = " con " & Cents & " centavos"
          End Select
 
          SpellNumber2 = UCase(Trim(Dollars & Cents))
      End Function
 
 
 
      '*******************************************
      ' Converts a number from 100-999 into text *
      '*******************************************
 
      Private Function GetHundreds(ByVal MyNumber)
          Dim Result As String
 
          If Val(MyNumber) = 0 Then Exit Function
          MyNumber = Right("000" & MyNumber, 3)
 
          ' Convert the hundreds place.
          If Mid(MyNumber, 1, 1) <> "0" Then
            If MyNumber = "100" Then
                Result = "cien "
            Else
            Select Case Mid(MyNumber, 1, 1)
                Case 1
                    Select Case Len(MyNumber)
                        Case 1
                            Result = "Un "
                        Case 3
                            Result = "Ciento "
                        Case 4
                            Result = ""
                        Case 6
                            Result = "Ciento "
                        Case 9
                            Result = "Ciento "
                    End Select
 
                Case 2
                    Result = "doscientos "
                Case 3
                    Result = "trescientos "
                Case 4
                    Result = "cuatrocientos "
                Case 5
                    Result = "quinientos "
                Case 6
                    Result = "seiscientos "
                Case 7
                    Result = "setecientos "
                Case 8
                    Result = "ochocientos "
                Case 9
                    Result = "novecientos "
            End Select
          End If
        End If
          ' Convert the tens and ones place.
          If Mid(MyNumber, 2, 1) <> "0" Then
              Result = Result & GetTens(Mid(MyNumber, 2))
          Else
              Result = Result & GetDigit(Mid(MyNumber, 3))
          End If
 
          GetHundreds = Result
      End Function
 
 
 
      '*********************************************
      ' Converts a number from 10 to 99 into text. *
      '*********************************************
 
     Private Function GetTens(TensText)
          Dim Result As String
 
          Result = ""           ' Null out the temporary function value.
          If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
              Select Case Val(TensText)
                  Case 10: Result = "Diez"
                  Case 11: Result = "Once"
                  Case 12: Result = "Doce"
                  Case 13: Result = "Trece"
                  Case 14: Result = "Catorce"
                  Case 15: Result = "Quince"
                  Case 16: Result = "Diez y seis"
                  Case 17: Result = "Diez y siete"
                  Case 18: Result = "Diez y ocho"
                  Case 19: Result = "Diez y nueve"
                  Case Else
              End Select
          Else                                 ' If value between 20-99...
              If Val(Right(TensText, 1)) = 0 Then
                Select Case Val(Left(TensText, 1))
                    Case 2: Result = "veinte"
                    Case 3: Result = "treinta"
                    Case 4: Result = "cuarenta"
                    Case 5: Result = "cincuenta"
                    Case 6: Result = "sesenta"
                    Case 7: Result = "setenta"
                    Case 8: Result = "ochenta"
                    Case 9: Result = "noventa"
                    Case Else
                End Select
              Else
                Select Case Val(Left(TensText, 1))
                    Case 2: Result = "veinti"
                    Case 3: Result = "treinta y "
                    Case 4: Result = "cuarenta y "
                    Case 5: Result = "cincuenta y "
                    Case 6: Result = "sesenta y "
                    Case 7: Result = "setenta y "
                    Case 8: Result = "ochenta y "
                    Case 9: Result = "noventa y "
                    Case Else
                End Select
              End If
 
              Result = Result & GetDigit _
                  (Right(TensText, 1))  ' Retrieve ones place.
          End If
          GetTens = Result
      End Function
 
 
 
 
      '*******************************************
      ' Converts a number from 1 to 9 into text. *
      '*******************************************
 
      Private Function GetDigit(Digit)
          Select Case Val(Digit)
              Case 1: GetDigit = "UN"
              Case 2: GetDigit = "DOS"
              Case 3: GetDigit = "TRES"
              Case 4: GetDigit = "CUATRO"
              Case 5: GetDigit = "CINCO"
              Case 6: GetDigit = "SEIS"
              Case 7: GetDigit = "SIETE"
              Case 8: GetDigit = "OCHO"
              Case 9: GetDigit = "NUEVE"
              Case Else: GetDigit = ""
          End Select
      End Function

Saludos,

Gonzalo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar