Giri
06-15-2011, 05:06 AM
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
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