FIND character in variable VBA

WarPigl3t

Well-known Member
Joined
May 25, 2014
Messages
1,611
I don't want to find a character in a cell
I type this function into cell D1... =Mjolnir(A1:B1)
Code:
Function Mjolnir(a As Excel.Range)
     aVal = a.Address(0, 0, xlA1, 0)
     [COLOR=#008000]'Now aVal equals "A1:B1" as a string of text
     'I want to return a variable that contains just the _
          row number of the first part of the range in the string text. _
          So I need to return the 1 in between the A and the : _
          I do this by first locating the : in the string of text.[/COLOR]
   [COLOR=#b22222][B]  strLength = Application.WorksheetFunction.Find(bVal, ":")[/B][/COLOR]
     [COLOR=#008000]'strLength should give me the position of the colon.  _
          It is located in position 3.  This code doesn't work _
          because it is not a range, it is a string.
     'I need something that can do that with a string, not a range.  It needs to be _
          dynamic because a user might have selected range AA25:BB25.  _
          This means I can't simply use left and right functions without knowing _
          first how to find the colon.[/COLOR]
End Function
 
Last edited:
When I use these...
result = a(2).column

Or
result = Range("A1:F1")(2).Column

they always return 2 as the column even though I changed the range to A1:F1.


Code:
[color=darkblue]With[/color] Range("A1:F10")
    result = .Cells(, .Columns.Count).Column
[color=darkblue]End[/color] [color=darkblue]With[/color]
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

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