find selects almost entire worksheet instead of just column D

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
as per title.
I have similar code in different part of my workbook and it works fine, but as soon as i started playign with offsets I have this problem.
VBA Code:
    Sub TEST()
    ActiveSheet.Columns("D:D").Select
Set cell = Selection.Find(what:="legs", After:=ActiveCell, LookIn:=xlFormulas, _
        lookat:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

If Not IsEmpty(cell.Offset(, 2)) And cell.Offset(, 2) <> 0 Then
    MsgBox "no legs"
Else
    MsgBox "yes legs"
End If

    End Sub
I assume i need some more stuff to make it work.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Is this what you want
Excel Formula:
If cell.Offset(, 2) <> "" And cell.Offset(, 2) <> 0 Then
 
Upvote 0
Is this what you want
Excel Formula:
If cell.Offset(, 2) <> "" And cell.Offset(, 2) <> 0 Then
not quite, that part worked fine it's just that ActiveSheet.Columns("D:D").Select actually selects:
1666875930631.png
 
Upvote 0
That's because you have used merged cells which are an abomination.
Use
VBA Code:
    Sub TEST()
Set cell = Columns("D").Find(what:="legs", After:=ActiveCell, LookIn:=xlFormulas, _
        lookat:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
 
Upvote 0
That's because you have used merged cells which are an abomination.
Use
VBA Code:
    Sub TEST()
Set cell = Columns("D").Find(what:="legs", After:=ActiveCell, LookIn:=xlFormulas, _
        lookat:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
Haha your probably right, I'll check this out tommorow. Gotta go home sometimes.
But I have a feeling it's going to work.
 
Upvote 0
Maybe this then
VBA Code:
Set cell = Columns("D").Find(what:="legs", After:=Cells(1, 4), LookIn:=xlFormulas, _
        lookat:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
 
Upvote 0
Maybe this then
VBA Code:
Set cell = Columns("D").Find(what:="legs", After:=Cells(1, 4), LookIn:=xlFormulas, _
        lookat:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
Object Variable or With Block Variable Not Set
 
Upvote 0
In that case I think you need to post ALL the code you are using.
And please not in picture form.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top