Title lookup

Flyingmeatball

Board Regular
Joined
Aug 15, 2007
Messages
65
I'm trying to make a dynamic Sumifs function, but using a match function is giving me wrong values. The problem is my columns are dynamic - the data I want won't always be in the same column. However, the header will stay the same. Here is the code I tried running to find which column number I will be searching through:

Sub test()
Dim colnum As Integer

colnum = Application.Match("capital markup", Range("A1:Z1"))

End Sub

However, the match returns strange things. Sometimes it won't find the data at all, and sometimes it returns 17, even if the data is in column C or D. Any suggestions?

Thanks so much!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi

Try an exact match:

Code:
colnum = Application.Match("capital markup", Range("A1:Z1")[B][SIZE=3][COLOR=blue],0[/COLOR][/SIZE][/B])

Remark: Instead of a worksheet function you could also use the Range.Find() method.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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