+ Reply to Thread
Results 1 to 8 of 8

Find heading, the subheading, display value

Hybrid View

mprpich Find heading, the subheading,... 11-28-2006, 06:45 AM
T-J I don't know if this is any... 11-28-2006, 12:10 PM
mprpich Hi TJ, This is almost... 11-28-2006, 12:24 PM
T-J Instead of the inputboxes use... 11-28-2006, 06:55 PM
mprpich Thank you again for all the... 11-29-2006, 09:38 AM
Meesam_ali Re: Find heading, the... 02-16-2014, 07:20 AM
arlu1201 Re: Find heading, the... 02-17-2014, 06:49 AM
Meesam_ali Re: Find heading, the... 02-17-2014, 09:58 AM
  1. #1
    Registered User
    Join Date
    11-28-2006
    Posts
    5

    Find heading, the subheading, display value

    Hi,

    I have a spreadsheet (excel 2000) and it has headings and subheadings in the same column, with values in the next column, as attached.

    What I need is to perform a lookup or search that recognises the heading, and finds the correct subheading, and displays the value next to that subheading. i.e.:

    If I want "BBB" heading, and "ghi" subheading, the value displayed would be 12.

    I have been trying to use the find function to find the heading, but cannot find code to search the Subheading:
    Cells.Find("BBB", , xlValues).Activate

    I have been rattling my brain trying to find any formula or code to perform this, any help would be much appreciated.

    Thank you in-advance.
    Matt
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    I don't know if this is any use:

    Sub Search()
        Dim rngHeading As Range, rngSubheading As Range
        Dim strHeading As String, strSubHeading As String
        
        strHeading = InputBox("Enter the heading to find")
        strSubHeading = InputBox("Enter the sub-heading to find")
        
        With Worksheets(1).Range("A1:A10000")   'search this range on sheet1
            Set rngHeading = .Find(What:=strHeading, After:=Range("A1"), LookIn:=xlValues, LookAt:=xlPart)   'heading search
            If Not rngHeading Is Nothing Then
                Set rngSubheading = .Find(What:=strSubHeading, After:=rngHeading, LookIn:=xlValues, LookAt:=xlPart)  'sub-heading search
                If Not rngSubheading Is Nothing Then
                    rngSubheading.Offset(, 1).Activate      'activate the value and display message
                    MsgBox "Heading: " & strHeading & vbCrLf & _
                            "Sub-heading: " & strSubHeading & vbCrLf & _
                            "Value: " & rngSubheading.Offset(, 1).Value, vbInformation
                Else
                    MsgBox "Heading " & strHeading & " was found, but" & vbCrLf & _
                            "Sub-heading " & strSubHeading & " was not found", vbExclamation
                End If
            Else
                MsgBox "Heading " & strHeading & " was not found", vbExclamation
            End If
        End With
    
        Set rngHeading = Nothing
        Set rngSubheading = Nothing
    End Sub

  3. #3
    Registered User
    Join Date
    11-28-2006
    Posts
    5
    Hi TJ,

    This is almost exaclty what I am after!! Except instead of a user inputing the figures via a txtbox, can the code link to cells on the spreadsheet that automatically configure the search and then source the outcome value into another cell.

    What you have already done is great, and I am sure I can figure out what I am after from this but any other help would be great.

    Cheers again, you're a legend!!
    Matt

  4. #4
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    Instead of the inputboxes use -

    strHeading = Sheets(1).Range("c1").Value
    strSubHeading = Sheets(1).Range("d1").Value

    and to write the value to the sheet -

    Sheets(1).Range("e1").Value = rngSubheading.Offset(, 1).Value

    Change the sheet and cell references as required.

  5. #5
    Registered User
    Join Date
    11-28-2006
    Posts
    5
    Thank you again for all the help, I have been spending ages trying to find this code and now it works like a dream!!!!

    Cheers,
    Matt

  6. #6
    Registered User
    Join Date
    12-03-2012
    Location
    Doha, Qatar
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Find heading, the subheading, display value

    Guys,
    Sorry to jump in on a very old thread. Can anybody tell me a simple way how to convert above mentioned subroutine to a function. I wanna use a custom function instead of subroutine as I want to use this function directly in sheet instead of calling a subroutine time and again.
    Any response is highly appreciated.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Find heading, the subheading, display value

    Meesam_Ali,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  8. #8
    Registered User
    Join Date
    12-03-2012
    Location
    Doha, Qatar
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Find heading, the subheading, display value

    Thanks madam. I will surely post a new thread with link to the current thread.

+ 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