in VBA index value in array for .Evaluate

quitethenovice

New Member
Joined
Jun 3, 2020
Messages
12
Office Version
  1. 365
Hello all

I'm using the VBA evaluate function to count matching rows. My question is about how to reference a value in an array. Is it a case of changing the way I declare the array or is there a way to index like I've tried?

Thanks!

PS. Below is an extract of the relevant parts of my module.

VBA Code:
Dim TechArray As Variant, AssetRng As String, Asset1 As String, Asset2 As String, Asset3 As String, LR1 As String

LR1 = ThisWorkbook.Sheets("Main").Range("A" & Rows.Count).End(xlUp).Row

TechArray = Array("John", "Bob", "Sandra", "Jason")
TechRng = "Q2:Q" & LR1
AssetRng = "E2:E" & LR1
Asset1 = """*sv*"""
Asset2 = """*s/v*"""
Asset3 = """*sluice*"""

Activeworkbook.Sheets("Fig").Range("G2").Value = ThisWorkbook.Sheets("Main").Evaluate("SUMPRODUCT(((ISNUMBER(SEARCH(" & Asset1 & "," & AssetRng & ")))" & _
                                         "+(ISNUMBER(SEARCH(" & Asset2 & "," & AssetRng & ")))+(ISNUMBER(SEARCH(" & Asset3 & "," & AssetRng & "))))" & _
                                         "*((ISNUMBER(SEARCH(" & TechArray(1) & "," & TechRng & ")))+(ISNUMBER(SEARCH(" & TechArray(4) & "," & TechRng & "))))"
 

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.
You are missing some brackets in the formula
VBA Code:
ActiveWorkbook.Sheets("Fig").Range("G2").Value = ThisWorkbook.Sheets("Main").Evaluate("SUMPRODUCT(((ISNUMBER(SEARCH(" & Asset1 & "," & AssetRng & ")))" & _
                                         "+(ISNUMBER(SEARCH(" & Asset2 & "," & AssetRng & ")))+(ISNUMBER(SEARCH(" & Asset3 & "," & AssetRng & "))))" & _
                                         "*((ISNUMBER(SEARCH(" & TechArray(1) & "," & TechRng & ")))+(ISNUMBER(SEARCH(" & TechArray(4) & "," & TechRng & ")))))")
 
Upvote 0
TechArray(4) might be a problem as well with only 4 elements in the array?
 
Upvote 0
Depends on if your running Option Base 1 or not.
If not then your array will be 0 to 3
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,705
Members
449,048
Latest member
81jamesacct

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