Loop through an Array, change values

Darth269

New Member
Joined
Oct 4, 2018
Messages
15
Hi there!

I want to loop through an array looking for the below values. IF it finds them, I want to change the value, if it doesn't, just move on.

[TABLE="width: 147"]
<colgroup><col></colgroup><tbody>[TR]
[TD]10 Very Easy[/TD]
[/TR]
[TR]
[TD]10 Demonstrated Well[/TD]
[/TR]
[TR]
[TD]10 Very Satisfied[/TD]
[/TR]
[TR]
[TD]1 Not Demonstrated[/TD]
[/TR]
[TR]
[TD]1 Not Satisfied[/TD]
[/TR]
[TR]
[TD]1 Not Easy

[/TD]
[/TR]
</tbody>[/TABLE]


The value will change to either 10 or 1 accordingly. Hope someone can help. The array is called FeedbackArray.
 
That sounds like you have a 2d array in which case try
Code:
   Dim Sp As Variant
   Dim i As Long
   FeedbackArray = (Range("E3:E8").Value)
   For i = LBound(FeedbackArray) To UBound(FeedbackArray)
      Sp = Split(FeedbackArray(i, [COLOR=#ff0000]1[/COLOR]))
      If Sp(0) = "1" Or Sp(0) = "10" Then FeedbackArray(i, [COLOR=#ff0000]1[/COLOR]) = Sp(0)
   Next i


You wonderful human you.

Thanks, thats got it.

with my limited understanding of the code, I'm having to create multiple instances of this for each of the "columns" that I need to scan through, but thats still saving loads of time!


Thank you
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
If you need to do it on all the columns in the array you could use
Code:
   Dim FeedbackArray As Variant
   Dim Sp As Variant
   Dim i As Long, j As Long
   FeedbackArray = (Range("E3:E8").Value)
   For i = LBound(FeedbackArray) To UBound(FeedbackArray)
      For j = LBound(FeedbackArray, 2) To UBound(FeedbackArray, 2)
         Sp = Split(FeedbackArray(i, j))
         If Sp(0) = "1" Or Sp(0) = "10" Then FeedbackArray(i, j) = Sp(0)
      Next j
   Next i
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,967
Members
452,539
Latest member
delvey

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