+ Reply to Thread
Results 1 to 2 of 2

Trying to search a range and find a specfic item based on a condition.

  1. #1
    Registered User
    Join Date
    06-06-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    1

    Trying to search a range and find a specfic item based on a condition.

    Here is the code: The condition item is "If c.Offset(-8, 0).Value = T Then" which is not working. If I take this out, the code works perfectly and inserts the new columns.

    Sub InsertCol()


    Dim d As Range
    Dim c As Range
    Dim S As String
    Dim T As String
    Dim findAddress As String
    Dim findAddress2 As String


    T = InputBox("Which Sequence?")
    On Error Resume Next
    Select Case StrPtr(T)
    Case 0
    'OK not pressed
    Exit Sub
    Case Else
    'OK pressed
    'Carry on your routine, variable response contains the InputText
    End Select


    S = InputBox("Which Date?")
    On Error Resume Next
    Select Case StrPtr(S)
    Case 0
    'OK not pressed
    Exit Sub
    Case Else
    'OK pressed
    'Carry on your routine, variable response contains the InputText
    End Select

    With Worksheets("QRE Field Level").Range("A9:ON9")
    Set c = .Find("*" & S & "*", LookIn:=xlValues)

    If Not c Is Nothing Then findAddress = c.Address

    If c.Offset(-8, 0).Value = T Then

    Do
    c.EntireColumn.Copy
    c.EntireColumn.Insert Shift:=xlToRight
    Application.CutCopyMode = False
    c.Offset(0, 0) = Application.WorksheetFunction.EoMonth(c, 1)
    c.Offset(201, 0) = c.Offset(0, 0)
    c.Interior.Color = RGB(255, 0, 0)

    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> findAddress

    End If

    End With

    End Sub

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Trying to search a range and find a specfic item based on a condition.

    I would guess that the range being found, declared as "c", has a row of 8 or less. Then when you try to offset 8 rows up it errors out because it is not possible. Just a guess though.

+ 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