+ Reply to Thread
Results 1 to 2 of 2

InStr Function

  1. #1
    zoot
    Guest

    InStr Function

    Hello All,
    Hopefully someone can help me as I have been struggling with this last bit
    of code.
    I am attempting to loop through an advanced filter field and on select
    certain cells that meet 2 additional criteria

    I have no problem doing this with one criteria but cannot figure out the
    second part.

    If my advanced filter comes out with the following:

    S0001
    S0002
    S0003
    ABC
    123
    N0001
    N0002

    I want to loop through this list and select only those cells that start with
    an "S" or an "N"... I am doing the code in a word document referencing
    Excel..what the code is supposed to do is take cell value and add .doc to
    the end and then insert that file into one word document.

    Here is what I have come up with so far:

    For icount = 1 To 7

    wording = xlObj.Worksheets("sheet1").Range("A" & icount).Value
    If wording = "" Then
    'do nothing

    ' A textual comparison starting at position
    ElseIf InStr(1, wording, "s") = False Then -----this is where I need help (I
    think)
    'do nothing

    Else
    Selection.InsertBreak Type:=wdPageBreak
    Selection.InsertFile FileName:=baseDir & wording, Range:="",
    ConfirmConversions:= _
    False, Link:=False, Attachment:=False
    End If

    If icount = 6 Then
    Exit For
    End If
    Next icount

    Thanks so much for any comments.



  2. #2
    Tom Ogilvy
    Guest

    Re: InStr Function

    If you are specifically looking for data that starts with S or N

    s1 = lcase(Left(wording,1))
    if s1 = "s" or s1 = "n") then


    End if


    If you want to stick with Instr, then

    if instr(1,wording,"s",vbTextCompare) = 1 then


    End if

    I don't see the point of checking for emtpy and then not "s"


    --
    Regards,
    Tom Ogilvy


    "zoot" <[email protected]> wrote in message
    news:59Mgg.239466$7a.68071@pd7tw1no...
    > Hello All,
    > Hopefully someone can help me as I have been struggling with this last bit
    > of code.
    > I am attempting to loop through an advanced filter field and on select
    > certain cells that meet 2 additional criteria
    >
    > I have no problem doing this with one criteria but cannot figure out the
    > second part.
    >
    > If my advanced filter comes out with the following:
    >
    > S0001
    > S0002
    > S0003
    > ABC
    > 123
    > N0001
    > N0002
    >
    > I want to loop through this list and select only those cells that start

    with
    > an "S" or an "N"... I am doing the code in a word document referencing
    > Excel..what the code is supposed to do is take cell value and add .doc to
    > the end and then insert that file into one word document.
    >
    > Here is what I have come up with so far:
    >
    > For icount = 1 To 7
    >
    > wording = xlObj.Worksheets("sheet1").Range("A" & icount).Value
    > If wording = "" Then
    > 'do nothing
    >
    > ' A textual comparison starting at position
    > ElseIf InStr(1, wording, "s") = False Then -----this is where I need help

    (I
    > think)
    > 'do nothing
    >
    > Else
    > Selection.InsertBreak Type:=wdPageBreak
    > Selection.InsertFile FileName:=baseDir & wording, Range:="",
    > ConfirmConversions:= _
    > False, Link:=False, Attachment:=False
    > End If
    >
    > If icount = 6 Then
    > Exit For
    > End If
    > Next icount
    >
    > Thanks so much for any comments.
    >
    >




+ 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