Results 1 to 3 of 3

Vba Searching Problem

Threaded View

  1. #1
    Registered User
    Join Date
    12-13-2007
    Posts
    4

    Vba Searching Problem

    Hi Highly Esteemed,

    I have an Excel workbook with two Columns A and B. I also have another column H which I want to populate depending on which keywords were found in A or B.

    A - contains the subject of a message.
    B - contains the message body itself (mean 1000 - 1200 characters).

    What I want to do is of this nature:

    Do Until end of used range
    Activate the Cell I want to populate
    Use instr() function to search cell A2 (increases with loop)
    If keyword found (eg. downloading) in A2 then H2 = internet
    If not found Make the search string column B (for the same record)
    Repeat the search for this column (same record)
    If keyword found, then populate H2
    else put "undefined" in H2
    .
    end if
    end if loop Now my VBA implementation works but is not very accurate - also the presence of too many if then...if then.... makes it inaccurate - I was wondering if anyone could help me code select case statements using instr() or any other suggestions. Here is a section of my code: Private Sub cmdReqClass_Click() 'RequestClass 'Sub RequestClass() Dim SearchString, SearchChar, MyPos Sheets("DataRecord").Select Range("H2").Select 'character strings containing root words to be searched. Searchinternet = "INTERN" Searchpassword = "PURC" SearchCharPrint = "PRINT" 'There are about 25 search strings in total Do Until Selection.Offset(0, -7).Value = "" SearchString = (UCase(Selection.Offset(0, -7).Value)) ' String to search in. ' A textual comparison starting at position 1 If (InStr(1, SearchString, Searchinternet, 1) > 0) Then ActiveCell.Value = "Internet Related" ElseIf ((InStr(1, SearchString, SearchCharPrint , 1) > 0) ActiveCell.Value = "Printing" Else ActiveCell.Value = "Undefined" HERE IS MY PROBLEM - I DONT KNOW HOW TO WRITE THE CODE TO SEARCH B2 FOR THE SAME RECORD NEATLY - I DONT KNOW HOW TO USE SELECT CASE IN THIS SITUATION AND IF IT IS APPROPRIATE! 'SearchString = (UCase(Selection.Offset(0, -13).Value))) Select Case InStr(1, UCase(Selection.Offset(0, -6).Value), SEARCHINTERNET, 1) Case Is > 0 ActiveCell.Value = "Internet Related" Case Is < 0 InStr(1, UCase(Selection.Offset(0, -6).Value), SearchPass, 1) Case Else ActiveCell.Value = "Undefined" End Select End If Selection.Offset(1, 0).Select Loop End Sub
    Last edited by VBA Noob; 12-13-2007 at 09:09 AM.

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