Change the lenght of the character

Venus_excel

Board Regular
Joined
Dec 18, 2013
Messages
74
Hi all,

Happy to see u again all.
Need your help here. Thanks in Advance.

here i need to change the character length in macro.
example

Column COutput(same in column c)
AB_1234AB_01234
AB1234AB_01234
AB01234AB_01234
AB_01234aAB_1234a
AB01234aAB_1234a
AB_012345AB_12345
AB 01234AB_01234

<tbody>
</tbody><colgroup><col><col></colgroup>

Hint :
1) _(underscore) should come at third character
2) Total character of output is 8 character
3) After _(underscore) if it is four character then 0 will come after underscore(_) and if it is five character then 0 wont come.


Please help me to sort out this.
 
Last edited:
Hi Rick,

Sorry to say this. i cant share sheet as it is very confidential.

Can you just copy Column C (that is the column with your values, correct?) with the troublesome values into a new workbook and send me that?
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi Rick,

I just send sample file contain column C value and expected result in Column D but actual result should be in Column C itself.

Let me know if u need more details.
 
Upvote 0
Okay, just to keep this thread complete, here is the information the OP sent me...

CDE
1
2Original Data Corrected Data
3
4AB_1234.1 AB_01234.1
5AB 1234.1 AB_01234.1
6AB_01234b.1 AB_1234b.1
7AB_01234 AB_01234
8AB_1234_111 AB_01234_111
9AB1234 AB_01234
10AB1234.1 AB_01234.1
11AB__1234.2 AB_01234.2
12AB_012345.1 AB_12345.1
13AB_1234 XXX 1 (UK70, UK72, UK71) AB_01234 XXX 1 (UK70, UK72, UK71)
14AB_12345.1 XXX 2 (UK76) AB_12345.1 XXX 2 (UK76)
15AB_12345_XXX4 AB_12345_XXX4
16AB_01234 AB_01234
17AB1234.0 AB_01234.0
18AB12345.1 AB_12345.1
19

<colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 221px;"><col style="width: 64px;"><col style="width: 228px;"></colgroup><tbody>
</tbody>

Excel tables to the web >> Excel Jeanie HTML 4

The left hand column is the original data and the right hand column is what the OP wants the data to look like afterwards (the corrected data should overwrite the original data in Column C though, it should not be placed in a separate column). This is the macro I came up with to do what the OP wanted (I sent it directly to the OP by email)...

Code:
Sub FixUnderscore()
  Dim X As Long, Z As Long, Lpart As String, Rpart As String, vArr As Variant
  vArr = Range("C1", Cells(Rows.Count, "C").End(xlUp))
  For X = 1 To UBound(vArr)
    Do While vArr(X, 1) Like "??[ _][ _]*"
      vArr(X, 1) = Left(vArr(X, 1), 2) & Mid(vArr(X, 1), 4)
    Loop
    If Len(vArr(X, 1)) Then
      Lpart = Left(vArr(X, 1), 2)
      Rpart = Mid(vArr(X, 1), 3 - (vArr(X, 1) Like "??[ _]*")) & " "
      For Z = 1 To Len(Rpart)
        If Not IsNumeric(Mid(Rpart & "X", Z, 1)) Then
          Rpart = Right("00000" & Left(Rpart, Z), 5 - (Mid(Rpart, Z, 1) Like "[. _]")) & Mid(Rpart, Z + 1)
          Exit For
        End If
      Next
    Else
      Lpart = ""
    End If
    If Len(Lpart) Then vArr(X, 1) = Trim(Lpart & "_" & Rpart)
  Next
  Range("C1", Cells(Rows.Count, "C").End(xlUp)) = vArr
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,558
Messages
6,125,507
Members
449,236
Latest member
Afua

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top