Results 1 to 2 of 2

Thread: extract row line from the formula

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    9

    extract row line from the formula

    Hello,

    in a cell, I have this formula:

    =SUM('sheet1'!$B158:$B161)

    I would like to extract the first reference of the line (158 in this case, but it could change) and put it into a variable.

    Thanks for your help.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: extract row line from the formula

    in VBA?

    this is kinda off the top of my head....
    VB Code:
    1. Public Function GetStart(sRng As String) As Integer
    2. Dim fml As String
    3. Dim cLoc As Integer
    4. Dim bLoc As Integer
    5.  fml = Range(sRng).Formula
    6.  cLoc = InStr(fml, ":")
    7.  For x = cLoc - 1 To 1 Step -1
    8.     If IsNumeric(Mid(fml, x, 1)) = False Then
    9.         bLoc = x + 1
    10.         Exit For
    11.     End If
    12. Next
    13. GetStart = CInt(Mid(fml, bLoc, cLoc - bLoc))
    14.  
    15. End Function
    16.  
    17. Private Sub test()
    18.     MsgBox GetStart("B6")
    19. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width