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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
What are you trying to do?
If I2 is empty it will put an X in I2, otherwise it will find the first X after I2 & put another X in 7 rows below.
 
Upvote 0
Are you sure that you have an entry in I2:I500 that is exactly equal to the capital "X"?

Note that in the code below, you do not need to check again with another IF statement. It can only either be TRUE or FALSE.
So if it is not TRUE, the only other alternative is FALSE (so you do not need the IF statement after the ELSE).
Code:
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]

Also, this:
Code:
If IsEmpty(Sheets("Watched").Range("I2")) = True Then
can be simplified to this:
Code:
If IsEmpty(Sheets("Watched").Range("I2")) Then
 
Upvote 0
What are you trying to do?
If I2 is empty it will put an X in I2, otherwise it will find the first X after I2 & put another X in 7 rows below.

Fluff, whats happening is, it does the procedure for the same column that I click my button on 3 times and then it does nothing after that! Not sure why it would do that!
 
Upvote 0
If I run the code on a blank sheet, the first time it will put an X in I2, the 2nd will put an X in I9 and the third time it will put an X in I16
After that it will do nothing & both codes are the same in that respect.
What are you trying to do?
 
Upvote 0
If I run the code on a blank sheet, the first time it will put an X in I2, the 2nd will put an X in I9 and the third time it will put an X in I16
After that it will do nothing & both codes are the same in that respect.
What are you trying to do?

I need it to do it up until it hits the range that I designated; $I$500
 
Upvote 0
I tried something a little different but it only works if there is a previous X in the column. This is on a blank sheet.

Code:
Sheets("Sheet1").Columns("D").Find("X", , , xlWhole, , xlPrevious, False, , False).Offset(7) = "X"
 
Last edited:
Upvote 0
How about
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 x.Row < 494 Then
                x.Offset(7, 0) = "X"
            Else
                MsgBox "Time to change the range!"
            End If
        End If
    End With
End Sub
But
 
Upvote 0
:confused: No idea where that came from. Ignore it. :laugh:
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,594
Members
452,656
Latest member
earth

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