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.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Is this a VBA array & does it have values like "Very Easy", "Demonstrated Well" etc that need to be changed to either 10 or 1 accordingly?
 
Upvote 0
Hi there!

Yes, it's a VBA array, and has entries of NUMBER + TEXT, i need to remove the text leaving only the number, but only from the specific examples given (there are some NUMBER + TEXT entries that need to remain).
 
Upvote 0
Hello,

The Following UDF Grabs the number. https://www.extendoffice.com/documents/excel/1622-excel-extract-number-from-string.html

Function ExtractNumber(Cell As Range)
Dim i As Long
Dim ResultNum As Long
Dim InputString As String
InputString = Cell.Value
For i = 1 To Len(InputString)
If IsNumeric(Mid(InputString, i, 1)) = True Then
ResultNum = ResultNum & Mid(InputString, i, 1)
End If
Next
ExtractNumber = ResultNum
End Function

Copy this code into a module, and select the cell to the right of your text and type "=ExtractNumber(A1)" and Click the cell that you want to extract. (I used A1 as example)
 
Last edited:
Upvote 0
Maybe something like
Code:
   Dim FeedbackArray As Variant
   Dim Sp As Variant
   Dim i As Long
   
   For i = LBound(FeedbackArray) To UBound(FeedbackArray)
      Sp = Split(FeedbackArray(i))
      If Sp(0) = "1" Or Sp(0) = "10" Then FeedbackArray(i) = Sp(0)
   Next i
 
Upvote 0
Hello,

The Following UDF Grabs the number. https://www.extendoffice.com/documents/excel/1622-excel-extract-number-from-string.html

Function ExtractNumber(Cell As Range)
Dim i As Long
Dim ResultNum As Long
Dim InputString As String
InputString = Cell.Value
For i = 1 To Len(InputString)
If IsNumeric(Mid(InputString, i, 1)) = True Then
ResultNum = ResultNum & Mid(InputString, i, 1)
End If
Next
ExtractNumber = ResultNum
End Function

Copy this code into a module, and select the cell to the right of your text and type "=ExtractNumber(A1)" and Click the cell that you want to extract. (I used A1 as example)



Thank you so much for taking the time to do this, however I'm trying to edit the data in an Array, whilst leaving the src data in the worksheet untouched.
 
Upvote 0
Did you see my suggestion in post#5?
 
Upvote 0
Maybe something like
Code:
   Dim FeedbackArray As Variant
   Dim Sp As Variant
   Dim i As Long
   
   For i = LBound(FeedbackArray) To UBound(FeedbackArray)
      Sp = Split(FeedbackArray(i))
      If Sp(0) = "1" Or Sp(0) = "10" Then FeedbackArray(i) = Sp(0)
   Next i


Hmmm, i'm getting error 9, subscript out of range... specifically on the line :

Code:
[COLOR=#333333] Sp = Split(FeedbackArray(i))[/COLOR]
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,951
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