Find % and Replace Code in loop format, need vb code

shrinivasmj

Board Regular
Joined
Aug 29, 2012
Messages
140
Hi

Need to creat vb code to Replace % and add code for each % in loop number format

Input File

%a,Qing-Ze Jiao m.j.l.

%a.b*,Zhou-Ling Tian k. l.
%a*.b,Yun ZhaoFaa Maa
%a.b.c*,Deepak T.N.L.
%a.b*.c,kiran m. l. k.#

out put

$#AI1.a,Qing-Ze Jiao m.j.l.
$#AI2.a.b*,Zhou-Ling Tian k. l.
$#AI3.a*.b,Yun ZhaoFaa Maa
$#AI4.a.b.c*,Deepak T.N.L.
$#AI5.a.b*.c,kiran m. l. k.#


code to replace % upto 100 in below code

( $#AI ) will be same and number need to add there to 100. with dot last.

$#AI1.
$#AI2.
$#AI3.
$#AI4.
$#AI5.
$#AI6.
$#AI7.
$#AI8.
$#AI9.
$#AI10.

<tbody>
</tbody>
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Two versions:

If all you're concerned with is the first char changing then...
Code:
Sub FirstCharToIncrement()
    Dim rgDATA As Range, i As Long
    Set rgDATA = Range("A2:A6") 'change to suit
    With rgDATA
        For i = 1 To .Rows.Count
            .Cells(i, 1) = "$#AI" & i & "." & Mid(.Cells(i, 1), 2)
        Next i
    End With
End Sub


If you really want to replace by "%" then...
(all "%" occurrences within each string will be replaced)
Code:
Sub PercentToIncrement()
    Dim rgDATA As Range, i As Long
    Set rgDATA = Range("A2:A6") 'change to suit
    With rgDATA
        For i = 1 To .Rows.Count
            .Cells(i, 1) = Replace(.Cells(i, 1), "%", "$#AI" & i & ".")
        Next i
    End With
End Sub


Each version will continue incrementing up to the row count.
 
Upvote 0

Forum statistics

Threads
1,215,527
Messages
6,125,334
Members
449,218
Latest member
Excel Master

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