Results 1 to 5 of 5

Thread: Object Variable Not Set

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Posts
    49
    Location

    Object Variable Not Set

    Hi Everyone,

    I have been trying to make some code to find any words that are in the second column of this spreadsheet but not in the first and then copy them into column G.

    Here's what I have so far. I haven't been able to really test if this work s because I am getting an error in the line:

    "searchCell = x.Value" where I get a run-time error 91 - Object or With variable not set.

    What is the significance of using "Set" when declaring something??

    Finally, how do you do Shift + Select + Down(Right,Left or Up) in VBA?

    PS: If this looks familiar, it was a worksheet posted by another user earlier.

    Thank you,

    Giri

    Option Explicit
    
    Public Sub Giri()
        Dim x As Range
        Dim Total As Integer
        Dim searchRange As Range
        Dim foundCell As Range
        Dim fCellVal As Range
        Dim searchCell As Range
        Worksheets("SEA0611").Range("D:D").Select
        For Each x In Selection.Cells
            searchCell = x.Value
            searchRange = Range("A1:A227")
            Set foundCell = searchRange.Find(searchCell)
            fCellVal = foundCell.Value
            If Not StrComp(searchCell, fCellVal, vbTextCompare) = 0 Then
                Range("G1").Select
                If Not ActiveCell.Value = "" Then
                    ActiveCell.Offset(1, 0).Select
                    searchCell.Paste
                Else
                    ActiveCell.Select
                    searchCell.Paste
                End If
            End If
        Next x
    End Sub
    Last edited by Aussiebear; 12-15-2024 at 09:50 PM.

Posting Permissions

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