placing "X" at offset point

jarhead58

Active Member
Joined
Sep 21, 2017
Messages
367
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone!!

The following code had been working;

Code:
Sub Prodigal()Dim x As Range


If IsEmpty(Sheets("Watched").Range("I2")) = True Then
    Sheets("Watched").Range("I2") = "X"
Else
[COLOR=#ff0000]    If IsEmpty(Sheets("Watched").Range("I2")) = False Then[/COLOR]
[COLOR=#ff0000]        Set x = Sheets("Watched").Range("I2:I26").Find("X", LookIn:=xlValues)[/COLOR]
[COLOR=#ff0000]        If x.Address <> "$I$26" Then[/COLOR]
[COLOR=#ff0000]            x.Offset(7, 0) = "X"[/COLOR]
[COLOR=#ff0000]ElseIf x.Address = "$I$26" Then[/COLOR]
    
    MsgBox "Time to change the range!"


End If
End If
End If
End Sub

But when I changed the range in the red section to the following;

Code:
Sub Prodigal()Dim x As Range


If IsEmpty(Sheets("Watched").Range("I2")) = True Then
    Sheets("Watched").Range("I2") = "X"
Else
[COLOR=#ff0000]    If IsEmpty(Sheets("Watched").Range("I2")) = False Then[/COLOR]
[COLOR=#ff0000]        Set x = Sheets("Watched").Range("I2:I500").Find("X", LookIn:=xlValues)[/COLOR]
[COLOR=#ff0000]        If x.Address <> "$I$500" Then[/COLOR]
[COLOR=#ff0000]            x.Offset(7, 0) = "X"[/COLOR]
[COLOR=#ff0000]ElseIf x.Address = "$I$500" Then[/COLOR]
    
    MsgBox "Time to change the range!"


End If
End If
End If
End Sub

It didn't work; no errors! Any ideas?

TIA
 
Getting a runtime error '91'

Object variable or With block variable not set
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
In that case you don't have an X in the range, try
Code:
Sub Prodigal()
    Dim x As Range
    
    With Sheets("Watched")
        If IsEmpty(.Range("I2")) Then
            .Range("I2") = "X"
        Else
            Set x = Range("I2:I500").Find("X", , xlValues, xlWhole, xlByRows, xlPrevious, False, , False)
            If Not x Is Nothing Then
                If x.Row < 494 Then
                    x.Offset(7, 0) = "X"
                Else
                    MsgBox "Time to change the range!"
                End If
            Else
                MsgBox "No X"
            End If
        End If
    End With
End Sub
 
Upvote 0
In that case you don't have an X in the range, try
Code:
Sub Prodigal()
    Dim x As Range
    
    With Sheets("Watched")
        If IsEmpty(.Range("I2")) Then
            .Range("I2") = "X"
        Else
            Set x = Range("I2:I500").Find("X", , xlValues, xlWhole, xlByRows, xlPrevious, False, , False)
            If Not x Is Nothing Then
                If x.Row < 494 Then
                    x.Offset(7, 0) = "X"
                Else
                    MsgBox "Time to change the range!"
                End If
            Else
                MsgBox "No X"
            End If
        End If
    End With
End Sub

Actually there are 3 previous 'X' but nothing is happening.
 
Upvote 0
I used it referring to a blank sheet and it did it for I2 but nothing after
 
Upvote 0
Not sure why that happened, I tested it on a blank sheet & it put Xs all the way to I499.
 
Upvote 0
Not sure why that happened, I tested it on a blank sheet & it put Xs all the way to I499.

Hmmm....I copy and pasted what you have but changed it to sheet1 instead of watched. It put the X in I2 but then No X pops up after that
 
Upvote 0
Oops, it's missing a . from Range on this line
Code:
Set x =[COLOR=#ff0000] .[/COLOR]Range("I2:I500").Find("
 
Upvote 0
Yup, I took it out to get the tool tip for the Find arguments & forgot to put it back in :banghead:
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,601
Members
452,658
Latest member
GStorm

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