Match Function in VBA...

fadee2

Active Member
Joined
Nov 7, 2020
Messages
404
Office Version
  1. 2021
Platform
  1. Windows
hi all,

I am trying to match a value in a range of cells, using vba.
my worksheet looks like this
Daily_Wages_Computations.xlsm
ABCDJ
1Name01/12/2001/01/2101/12/20
2A300001000
3B21500200
4C12000500
5D265001000
6E220006000
7F220005000
8G220006000
Sheet4


and this is my code

VBA Code:
Sub matchVal()
Dim lookmon As Range

Set look_mon = Sheets("sheet4").Range("b1:f1")     'lookup range
lookval = Range("b1")                'lookup value

Sheets("sheet4").Range("f20") = WorksheetFunction.Match(lookval, look_mon, 0)

End Sub
the motive is to sum values in column if value in b1 or c1 matches the vakue in j1.
the code returns unable to get match property error, please refer to below image.
1608551522060.png

I am unable to figure out the missing link in the above code.
I can use index to return the value, which is working fine also, but I am trying to figure out what has gone wrong with Match function. any help is appreciated.
 
A question, in case if the lookup value is created
VBA Code:
lookval = DateValue("1/" & Month(minday) & "/" & Year(minday))
where minday is calculated like
VBA Code:
minday = Application.WorksheetFunction.Min(ActiveSheet.Range("fulldates"))
what changes should i make to the code below??
VBA Code:
s = WorksheetFunction.Match(CLng(lookval), look_mon, 0)
Sheets("sheet4").Range("j2") = WorksheetFunction.Sum(Range(Cells(2, s), Cells(lr, s)))
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Why do you need to make any changes?
 
Upvote 0
I want to make the lookup value more dynamic, with
VBA Code:
minday = Application.WorksheetFunction.Min(ActiveSheet.Range("fulldates"))
where fulldates is a named range on another sheet.

Nevermind though, ended up creating the right piece of code.

VBA Code:
minday = Application.WorksheetFunction.Min(ActiveSheet.Range("fulldates"))
Set look_mon = Sheets("sheet4").Range("b2:f2")     'lookup range
If IsError(Application.Match(minday, look_mon, 0)) Then
av = Format((grandtotal) / Application.WorksheetFunction.NetworkDays_Intl(minday, maxday, 11), "#,#.00")

Else

s = WorksheetFunction.Match(minday, look_mon, 0)
t = WorksheetFunction.Sum(Sheets("sheet4").Range(Sheets("sheet4").Cells(3, s + 1), Sheets("sheet4").Cells(lr, s + 1)))

av = Format((grandtotal + t) / Application.WorksheetFunction.NetworkDays_Intl(minday, maxday, 11), "#,#.00")
End If

Thanks for the help....
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

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