programming

5 pts.
Tags:
Excel macros
Microsoft Excel
VBA
Visual Basic for Applications
Tag# 301-22-AB02-103, I want this Tag format in this formate XXX-XX-NNXX-XXX, it means in place of Numbers i want 'X' and in Place of alphabet i want 'N', do you know how can you we do that in Excel? i wana to change numeric values in 'X' and alphabet in 'N' form, and my friend did already, through visual basic codes, suppose if i wirte 9393-ksksks-333ss- so it will appear like XXXX-NNNNNN-XXXNN, format
ASKED: July 10, 2008  6:48 AM
UPDATED: July 15, 2008  11:00 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Answer to your question is so simple.
In your excel file, start Visual Basic Editor from ‘Tools’ Menu –> ‘Macro’ –> ‘Visual Basic Editor’.
In Visual Basic add a module from ‘Insert’ Menu –> ‘Module’.
In that Module copy & paste following code.
‘*********************************************************************************

Public Function FormatTag(Tag As String) As String
Dim L As Integer ‘lenght of string
Dim i As Integer ‘to use in for loop

Tag = VBA.Trim(Tag)
L = VBA.Len(Tag)
FormatTag = “”

For i = 1 To L
If VBA.Asc(VBA.UCase(VBA.Mid(Tag, i, 1))) >= 65 And VBA.Asc(VBA.UCase(VBA.Mid(Tag, i, 1))) <= 90 Then
FormatTag = FormatTag & “N”
ElseIf VBA.Asc(VBA.Mid(Tag, i, 1)) >= 48 And VBA.Asc(VBA.Mid(Tag, i, 1)) <= 57 Then
FormatTag = FormatTag & “X”
Else
FormatTag = FormatTag & VBA.Mid(Tag, i, 1)
End If
Next
End Function

‘*********************************************************************************

Then close Visual Basic Editor, save your excel file.
Then in a cell, suppose ‘A1′ write the tag. In other cell, suppose ‘B1″ call the function written above by writing ‘=FormatTag(A1)’. You will get want you want in cell ‘B1′.
Bye.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following