Replacing one value to multiple values in rotations

Rashidz

New Member
Joined
Feb 8, 2018
Messages
9
Hi I would like to replace one value with multiple values in rotation,

In sheet 1, I have a value "DATA 10" in column A, row 2, 5, 7, 10, 15, 20, 23 and so on.

How can i replace this value (DATA 10) with multiple values (10 LADY, 10 CHILDREN, 10 MAN and 10 HAZMAT) in rotation, so that

row 2 will be replace to 10 LADY
row 5 = 10 CHILDREN
row 7 = 10 MAN
row 10 = 10 HAZMAT
row 15 = 10 LADY
row 20 = 10 CHILDREN
row 23 = 10 MAN
and so on in rotation


Thank you in advance,

Rashidz
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
1. Formula or VBA solution ?

2. Regardiing the phrase "and so on"

Your data starts on row 2 and the row increases with the following steps +3, +2, +3, +5, +5
The next row increase by +3
So is that sequence of +3 +2 +3 +5 +5 repeating again or is it something different?
 
Upvote 0
1. Formula or VBA solution ?

2. Regardiing the phrase "and so on"

Your data starts on row 2 and the row increases with the following steps +3, +2, +3, +5, +5
The next row increase by +3
So is that sequence of +3 +2 +3 +5 +5 repeating again or is it something different?

1. Well it can be a formula or VBA, whichever works

2. "and so on" mean these data will reach till rows 100

There is no patterns to these step "+3, +2, +3, +5". It can be anywhere in the rows. its not repeating.

To be precise, in my "DATA" sheet rows, I have "DATA 10", "DATA 20" and "DATA 30"

For DATA 10, i need to replace with these:

10 LADY
10 CHILDREN
10 MAN
10 HAZMAT

For DATA 20, need to replace with these:

20 GLOBAL
20 EQUALITY
20 IN DEPTH

And for DATA 30. need to replace with these:

30 BROADER
30 INSPIRATIONAL
30 STORY MATTER

All each DATA need to be replace as a rotation, one after another.

Thanks
 
Upvote 0
Hi & welcome to the board.

This should do your DATA 10
Code:
Sub replaceData()

   Dim Ary10 As Variant
   Dim Cnt As Long
   Dim Qty As Long
   Dim Fnd As Range
   Dim i As Long
   
   Ary10 = Array("10 LADY", "10 CHILDREN", "10 MAN", "10 HAZMAT")
   Qty = WorksheetFunction.CountIf(Columns(1), "DATA 10")
   For Cnt = 1 To Qty
      Set Fnd = Columns(1).Find("DATA 10", , , xlWhole, , , False, , False)
      If Not Fnd Is Nothing Then
         Fnd.Value = Ary10(i)
         i = i + 1
         If i > UBound(Ary10) Then i = 0
      End If
   Next Cnt

End Sub
 
Upvote 0
Hi & welcome to the board.

This should do your DATA 10
Code:
Sub replaceData()

   Dim Ary10 As Variant
   Dim Cnt As Long
   Dim Qty As Long
   Dim Fnd As Range
   Dim i As Long
   
   Ary10 = Array("10 LADY", "10 CHILDREN", "10 MAN", "10 HAZMAT")
   Qty = WorksheetFunction.CountIf(Columns(1), "DATA 10")
   For Cnt = 1 To Qty
      Set Fnd = Columns(1).Find("DATA 10", , , xlWhole, , , False, , False)
      If Not Fnd Is Nothing Then
         Fnd.Value = Ary10(i)
         i = i + 1
         If i > UBound(Ary10) Then i = 0
      End If
   Next Cnt

End Sub

Thank you so much Fluff. This is what I actually need. Perfect.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Hi & welcome to the board.

This should do your DATA 10
Code:
Sub replaceData()

   Dim Ary10 As Variant
   Dim Cnt As Long
   Dim Qty As Long
   Dim Fnd As Range
   Dim i As Long
   
   Ary10 = Array("10 LADY", "10 CHILDREN", "10 MAN", "10 HAZMAT")
   Qty = WorksheetFunction.CountIf(Columns(1), "DATA 10")
   For Cnt = 1 To Qty
      Set Fnd = Columns(1).Find("DATA 10", , , xlWhole, , , False, , False)
      If Not Fnd Is Nothing Then
         Fnd.Value = Ary10(i)
         i = i + 1
         If i > UBound(Ary10) Then i = 0
      End If
   Next Cnt

End Sub

I actually try to add more to this formula but it gives me error (Run-Time error '9': Subscript out of range).
Is it possible to add more to it like the one below?

Code:
Sub replaceData()

   Dim Ary10 As Variant
   Dim Cnt As Long
   Dim Qty As Long
   Dim Fnd As Range
   Dim i As Long
   
   Ary10 = Array("10 LADY", "10 CHILDREN", "10 MAN", "10 HAZMAT")
   Qty = WorksheetFunction.CountIf(Columns(1), "DATA 10")
   For Cnt = 1 To Qty
      Set Fnd = Columns(1).Find("DATA 10", , , xlWhole, , , False, , False)
      If Not Fnd Is Nothing Then
         Fnd.Value = Ary10(i)
         i = i + 1
         If i > UBound(Ary10) Then i = 0
      End If
   Next Cnt

   Ary10 = Array("30 STORY MATTER", "30 CLIMATE CHANGE", "30 INSPIRATIONAL", "30 PERSPECTIVE")
   Qty = WorksheetFunction.CountIf(Columns(1), "DATA 30")
   For Cnt = 1 To Qty
      Set Fnd = Columns(1).Find("DATA 30", , , xlWhole, , , False, , False)
      If Not Fnd Is Nothing Then
         Fnd.Value = Ary10(i)
         i = i + 1
         If i > UBound(Ary10) Then i = 0
      End If
   Next Cnt

End Sub
 
Upvote 0
Another way (with formulas in a new column - if possible):

1) Create the tables DATA10, DATA20 and DATA30 with the names DATA_10, DATA_20 and DATA_30


2) Put the formula below in B2 and copy down. And then, copy the range B2:B19 to the range E2:E19 and to the range H2:H19:

=IF(A2="","",IFERROR(VLOOKUP(MOD(COUNTIF(A$2:A2,A2)-1,
MAX(INDEX(INDIRECT(SUBSTITUTE(A2," ","_")),,1)))+1,
INDIRECT(SUBSTITUTE(A2," ","_")),2,0),""))


ABCDEFGHIJKL
1DataNew DataDataNew DataDataNew DataTables
2DATA 1010 LADYDATA 2020 GLOBALDATA 3030 BROADERRange Name110 LADY
3DATA_10210 CHILDREN
4DATA 1010 CHILDRENDATA 2020 EQUALITYDATA 3030 INSPIRATION310 MAN
5410 HAZMAT
6
7DATA 1010 MANDATA 2020 IN DEPTHDATA 3030 STORY MATTERRange Name120 GLOBAL
8DATA_20220 EQUALITY
9DATA 1010 HAZMATDATA 2020 GLOBALDATA 3030 BROADER320 IN DEPTH
10
11Range Name130 BROADER
12DATA_30230 INSPIRATION
13DATA 1010 LADYDATA 2020 EQUALITYDATA 3030 INSPIRATION330 STORY MATTER
14
15DATA 1010 CHILDRENDATA 2020 IN DEPTHDATA 3030 STORY MATTER
16
17
18DATA 1010 MANDATA 2020 GLOBALDATA 3030 BROADER
19DATA 1010 HAZMATDATA 2020 EQUALITYDATA 3030 INSPIRATION
*************************************************************************************************************

<tbody>
</tbody>


I hope this helps.

Markmzz
 
Upvote 0
This will reverse the changes
Code:
Sub ReverseChange()
   Dim Ary10 As Variant
   Dim Cnt As Long
   
   Ary10 = Array("10 LADY", "10 CHILDREN", "10 MAN", "10 HAZMAT")
   For Cnt = 0 To UBound(Ary10)
      Columns(1).Replace Ary10(Cnt), "DATA 10", , , False, , False, False
   Next Cnt

End Sub
The code you supplied in post#8 works for me. Which line gave the error?
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,246
Members
449,093
Latest member
Vincent Khandagale

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