Search : in
By :

Excel Macro(?) convert text string to date

Last answer on Jul 3, 2009 10:58:26 pm BST painkiller, on Apr 2, 2009 1:38:34 pm BST 
 Report this message to moderators

Hello,
Maybe this problem is trivial to solve, but I haven't done anything with Excel Macros since University and that was long time ago. Maybe macros aren't even needed.

So, there is one column with ~5000 records, everyone of which all consist of 11 numbers (like 21019910614 ). It is personal identifier in my country and begins with date (in previous example it would look like 21.01.99 - dd.mm.yy ) Other 5 numbers are like ID number.
What is needed? From all these 5000 Records I need to remove last 5 (because I need just date ones) numbers and all remaining turn into Date Format (like I wrote - dd.mm.yy). It is the first part and if we could find any solution to make these records to dates, it would be great.

Hope, I explained the problem enough.

Configuration: Windows XP
MS Excel 2003 Professional

Best answers for « Excel Macro(?) convert text string to date » in :
Excel tips : How to insert date in a cell ShowExcel tips : How to insert date in a cell Below are some tips on how to insert date and time in an excel cell for a specific purpose:- To insert current date, press CTRL ¯+ ;¯ in the chosen cell. To insert current time, press CTRL¯+...
Delete duplicates in an Excel column ShowDelete duplicates in an Excel column To remove duplicates in an Excel column: Click on the Data menu Filter Advanced Filter In this menu, select the column where the duplicates Check the box "Extract without duplication"...
How to convert Excel into PDF? ShowHow to convert Excel into PDF? Here is a small tips about how to convert your excel files into PDF for your presentation. Step 1 PDF995 is software that gets installed on your computer which enables you to print any sources of document to...
Download DBF to Excel Converter ShowDescription The application is designed by WhiteTown Software. DBF to Excel is a tool that allows you to convert your file easily. Simple and easy to use, the application has been awarded from various places. Offering an intuitive interface, the...
Download ABC Amber Excel Converter ShowDo you know that your Excel spreadsheet can be converted into any format? Only ABC Amber Excel Converter can gather these many conversions into a single application. ABC Amber Excel Converter is a program to convert your XLS files into several...

1

WutUp WutUp, on Apr 2, 2009 11:48:57 pm BST

This assumes that the data is in column A and that row 1 has header info. So, it starts checking in row 2 of
column A. Also, by using the Do loop until empty assumes there are no blank cells in the column. Otherwise,
the For loop will need to be used.

Hope this helps!

Sub CreateDate()

Dim j
j = 2

Do Until Range("A" & j) = ""

Range("A" & j) = Left(Range("A" & j), 2) & "." & Mid(Range("A" & j), 3, 2) & "." & Mid(Range("A" & j), 5, 2)

j = j + 1

Loop


End Sub

Reply to WutUp WutUp

2

 noecortez, on Jul 3, 2009 10:58:26 pm BST

Puedes utilizar el siguiente codigo, solo tecleas ALT+F11 y le das insertar - modulo. Copias el siguiente codigo:
Function ntot(Numero)
Dim Texto
Dim Millones
Dim Miles
Dim Cientos
Dim Decimales
Dim Cadena
Dim CadMillones
Dim CadMiles
Dim CadCientos
Texto = Numero
Texto = FormatNumber(Texto, 2)
Texto = Right(Space(14) & Texto, 14)
Millones = Mid(Texto, 1, 3)
Miles = Mid(Texto, 5, 3)
Cientos = Mid(Texto, 9, 3)
Decimales = Mid(Texto, 13, 2)
CadMillones = ConvierteCifra(Millones, 1)
CadMiles = ConvierteCifra(Miles, 1)
CadCientos = ConvierteCifra(Cientos, 0)
If Trim(CadMillones) > "" Then
If Trim(CadMillones) = "UN" Then
Cadena = CadMillones & " MILLON"
Else
Cadena = CadMillones & " MILLONES"
End If
End If
If Trim(CadMiles) > "" Then
Cadena = Cadena & " " & CadMiles & " MIL"
End If
If Trim(CadMiles & CadCientos) = "UN" Then
Cadena = Cadena & "UNO CON " & Decimales & "/100"
Else
If Miles & Cientos = "000000" Then
Cadena = Cadena & " " & Trim(CadCientos) & " DE PESOS " & Decimales & "/100"
Else
Cadena = Cadena & " " & Trim(CadCientos) & " PESOS " & Decimales & "/100"
End If
End If
ntot = "(" + Trim(Cadena) + ")"
End Function

Function ConvierteCifra(Texto, SW)
Dim Centena
Dim Decena
Dim Unidad
Dim txtCentena
Dim txtDecena
Dim txtUnidad
Centena = Mid(Texto, 1, 1)
Decena = Mid(Texto, 2, 1)
Unidad = Mid(Texto, 3, 1)
Select Case Centena
Case "1"
txtCentena = "CIEN"
If Decena & Unidad <> "00" Then
txtCentena = "CIENTO"
End If
Case "2"
txtCentena = "DOSCIENTOS"
Case "3"
txtCentena = "TRESCIENTOS"
Case "4"
txtCentena = "CUATROCIENTOS"
Case "5"
txtCentena = "QUINIENTOS"
Case "6"
txtCentena = "SEISCIENTOS"
Case "7"
txtCentena = "SETECIENTOS"
Case "8"
txtCentena = "OCHOCIENTOS"
Case "9"
txtCentena = "NOVECIENTOS"
End Select

Select Case Decena
Case "1"
txtDecena = "DIEZ"
Select Case Unidad
Case "1"
txtDecena = "ONCE"
Case "2"
txtDecena = "DOCE"
Case "3"
txtDecena = "TRECE"
Case "4"
txtDecena = "CATORCE"
Case "5"
txtDecena = "QUINCE"
Case "6"
txtDecena = "DIECISEIS"
Case "7"
txtDecena = "DIECISIETE"
Case "8"
txtDecena = "DIECIOCHO"
Case "9"
txtDecena = "DIECINUEVE"
End Select
Case "2"
txtDecena = "VEINTE"
If Unidad <> "0" Then
txtDecena = "VEINTI"
End If
Case "3"
txtDecena = "TREINTA"
If Unidad <> "0" Then
txtDecena = "TREINTA Y "
End If
Case "4"
txtDecena = "CUARENTA"
If Unidad <> "0" Then
txtDecena = "CUARENTA Y "
End If
Case "5"
txtDecena = "CINCUENTA"
If Unidad <> "0" Then
txtDecena = "CINCUENTA Y "
End If
Case "6"
txtDecena = "SESENTA"
If Unidad <> "0" Then
txtDecena = "SESENTA Y "
End If
Case "7"
txtDecena = "SETENTA"
If Unidad <> "0" Then
txtDecena = "SETENTA Y "
End If
Case "8"
txtDecena = "OCHENTA"
If Unidad <> "0" Then
txtDecena = "OCHENTA Y "
End If
Case "9"
txtDecena = "NOVENTA"
If Unidad <> "0" Then
txtDecena = "NOVENTA Y "
End If
End Select

If Decena <> "1" Then
Select Case Unidad
Case "1"
If SW Then
txtUnidad = "UN"
Else
txtUnidad = "UNO"
End If
Case "2"
txtUnidad = "DOS"
Case "3"
txtUnidad = "TRES"
Case "4"
txtUnidad = "CUATRO"
Case "5"
txtUnidad = "CINCO"
Case "6"
txtUnidad = "SEIS"
Case "7"
txtUnidad = "SIETE"
Case "8"
txtUnidad = "OCHO"
Case "9"
txtUnidad = "NUEVE"
End Select
End If
ConvierteCifra = txtCentena & " " & txtDecena & txtUnidad
End Function

Luego lo mandas llamar desde tu hoja como =ntot(B15), por ejemplo donde B15 es la celda donde esta el numero que quieres convertir a texto.
Para cualquier otro desarrollo estoy a tus ordenes, me puedes escribir a noecortez(arroba)leipzig.com.mx o llamarme al 011+52+55+55654892

Reply to noecortez