+ Reply to Thread
Results 1 to 3 of 3

Find characters in formula

Hybrid View

  1. #1
    Registered User
    Join Date
    08-19-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    16

    Question Find characters in formula

    In the attached file, I am looking for the 2 numbers after the FW in the formula in cells in column G.

    Example:
    Cell G258 has the formula:
    ='Z:\PRODMONTH\Production2009\[Fw37_09.xls]Sun'!$C$16+'Z:\PRODMONTH\Production2009\[Fw37_09.xls]Sun'!$D$16
    I am trying to set a parameter (J in my instance) to equal the 37 in my VBA code, first two digits after the 'Fw'. (Essentially, this is the Fiscal Week - but this can change from site to site - some start in October, others in Jan, sometimes late December, etc), so I need these numbers and not create another application to create the Fiscal Week.
    Attached Files Attached Files
    Last edited by Leith Ross; 09-09-2009 at 03:43 PM. Reason: Added Code Tags

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find characters in formula

    Perhaps

    Dim j As Long
    j = Val(Split(Cells(258,"G").Formula,"Fw")(1))

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Find characters in formula

    Hello mtbe,

    Use this UDF (User Defiend Function) in a cell on your worksheet or in your VBA code to return the Fiscal Week number from a cell. If "FW" is found the week number is returned, otherwise a zero is returned.
    Function GetFiscalWeek(Cell As Range)
    
      Dim I As Integer
      
        I = InStr(1, Cell.Formula, "FW", vbTextCompare)
        GetFiscalWeek = IIf(I > 0, Mid(Cell.Formula, I + 2, 2), 0)
        
    End Function
    Example - Worksheet Function
      'Cell $E$258 formula
       =GetFiscalWeek(G258)
    
      'Cell $E$258 value
       37
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1