Use VBA to create array, search through array and make changes to data values

elevate_yourself

New Member
Joined
Oct 9, 2014
Messages
15
Hello,

I am very new to VBA and am looking to find a way to search through an array using a range of cells and then make updates to the cells if there is a match. As an example:



ABCDE
1Change NamesArray of NamesNumber 1Number 2Number 3
2TimmyJohn567
3JohnBilly567
4MarkMike567
5Mark567
6Timmy567

<tbody>
</tbody>

What I would like to be able to do is search the "Array of Names" column (which I would like to make as an array) and for any names that match the "Change Names" column, and update the values in the Number columns to 0 for all. So in the end it would look like:


ABCDE
1Change NamesArray of NamesNumber 1Number 2Number 3
2TimmyJohn000
3JohnBilly567
4MarkMike567
5Mark000
6Timmy000

<tbody>
</tbody>

I hope this is clear enough - if more clarification is needed please let me know :)
 
Morning Hiker95,

I have tried to see if there is a way for me to remove all the sensitive information in the spreadsheet and unfortunately I would basically have to create the spreadsheet from scratch to do so. So unfortunately I wont be able to provide screenshots. All I can tell you is that the modified code does work on a new spreadsheet and that the one I am using has about 20 tabs and a lot of pivot tables and links to different databases. If you happen to know a way to fix the "Subscript out of range" error on a general level that would be helpful. I have read other posts suggesting that its caused by moving from one sheet to another and the best way to fix it is to just append everything with the specific spreadsheet your using. However, I have dont that and it does not fix the issue in this case. Ill keep looking around to see what I can find but at this point, regrettably, I cant provide any more specific details.

Cheers,
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Just wanted to post an update saying I found a way to make the code work. Instead of using the array I used a range find. Final version of the code below.

Code:
Option ExplicitSub testing()


Dim b As Variant
Dim i As Long
Dim lr As Long
Dim lc As Long
Dim a As Range


Application.ScreenUpdating = False


lr = Sheets("Sheet2").Cells(Rows.Count, "B").End(xlUp).Row


lc = Sheets("Sheet2").Cells(1, Columns.Count).End(xlToLeft).Column


'b = Sheets("Sheet2").Range("B8:B" & lr)


For i = 8 To lr
  Set a = Sheets("Sheet1").Range("C32:C34").Find(Sheets("Sheet2").Range("B" & i), LookAt:=xlWhole)
  If Not a Is Nothing Then
    Sheets("Sheet2").Cells(i, 9).Value = 0
    Sheets("Sheet2").Cells(i, 10).Value = 0
    Sheets("Sheet2").Cells(i, 11).Value = 0
    Sheets("Sheet2").Cells(i, 12).Value = 0
    Set a = Nothing
  End If
Next i


Application.ScreenUpdating = True


End Sub
 
Upvote 0
elevate_yourself,

Thanks for the feedback.

Glad you were able to find a solution that worked correctly.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,835
Members
449,051
Latest member
excelquestion515

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