|
-
May 10th, 2013, 03:13 AM
#1
Thread Starter
Lively Member
[RESOLVED] Return the column position of found value within a range
Hi
I have a named range that sits in range D1 to H1. My program uses the FIND method to check that a value exists in the named range. When the value exists then I want to return the position within the range but the following is giving me the position on the worksheet.
Code:
DiscountColumn = Sheet4.range("ExportHeadings").Find(What:=DiscountString, MatchCase:=False).Column
So if the value is found in the first position within the named range then I expect the 1 to be returned and not the value 4.
I know I could loop through the range to find the value as it's a small range but I read that the FIND method is much more efficient.
Is it possible to return the position from within the named range?
Thanks
-
May 10th, 2013, 04:14 AM
#2
Re: Return the column position of found value within a range
you would need to compare the found column with the range column like
Code:
DiscountColumn = Sheet4.range("ExportHeadings").Find(What:=DiscountString, MatchCase:=False).Column - Sheet4.range("ExportHeadings").Column +1
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|