Code not working

H

Howard

Here is the code I am having trouble with. It returns all "X"'s in the offset ranges, whereas there should be three "O"'s and one "", (blank).

Where:
J = range A9 and A9 value is "B"
RangerTest is a named range A1 to O1 of sheet1
RangerTest has these values: ABCDEBFGHIJBKL and O1 is blank

When I run the code the offset values are: XXXXXXXXXXXXXX and the last offset
O1 is blank. The desired out come should be: XOXXXOXXXXXOXX (with the last offset blank in this example.

Sub Testx()
Dim J As String
Dim RangerTest As Range, Cell As Range
J = Range("A9").Value

For Each Cell In Range("RangerTest")
If Cell.Value = J Then Cell.Offset(5, 0).Value = "O"
If Cell.Value <> J Then Cell.Offset(5, 0).Value = "X"
If Cell.Value = "" Then Cell.Offset(5, 0).Value = ""
Next

End Sub

Can't figure where I am going wrong???

Regards
Howard
 
D

Don Guillett

Here is the code I am having trouble with. It returns all "X"'s in the offset ranges, whereas there should be three "O"'s and one "", (blank).



Where:

J = range A9 and A9 value is "B"

RangerTest is a named range A1 to O1 of sheet1

RangerTest has these values: ABCDEBFGHIJBKL and O1 is blank



When I run the code the offset values are: XXXXXXXXXXXXXX and the last offset

O1 is blank. The desired out come should be: XOXXXOXXXXXOXX (with the last offset blank in this example.



Sub Testx()

Dim J As String

Dim RangerTest As Range, Cell As Range

J = Range("A9").Value



For Each Cell In Range("RangerTest")

If Cell.Value = J Then Cell.Offset(5, 0).Value = "O"

If Cell.Value <> J Then Cell.Offset(5, 0).Value = "X"

If Cell.Value = "" Then Cell.Offset(5, 0).Value = ""

Next



End Sub



Can't figure where I am going wrong???



Regards

Howard

Send file to dguillett @gmail.com with this msg and I'll look.
 
D

Don Guillett

Here is the code I am having trouble with. It returns all "X"'s in the offset ranges, whereas there should be three "O"'s and one "", (blank).



Where:

J = range A9 and A9 value is "B"

RangerTest is a named range A1 to O1 of sheet1

RangerTest has these values: ABCDEBFGHIJBKL and O1 is blank



When I run the code the offset values are: XXXXXXXXXXXXXX and the last offset

O1 is blank. The desired out come should be: XOXXXOXXXXXOXX (with the last offset blank in this example.



Sub Testx()

Dim J As String

Dim RangerTest As Range, Cell As Range

J = Range("A9").Value



For Each Cell In Range("RangerTest")

If Cell.Value = J Then Cell.Offset(5, 0).Value = "O"

If Cell.Value <> J Then Cell.Offset(5, 0).Value = "X"

If Cell.Value = "" Then Cell.Offset(5, 0).Value = ""

Next



End Sub



Can't figure where I am going wrong???



Regards

Howard

I think OP forgot to input a value in cell j (a10)
 
D

Don Guillett

Here is the code I am having trouble with. It returns all "X"'s in the offset ranges, whereas there should be three "O"'s and one "", (blank).



Where:

J = range A9 and A9 value is "B"

RangerTest is a named range A1 to O1 of sheet1

RangerTest has these values: ABCDEBFGHIJBKL and O1 is blank



When I run the code the offset values are: XXXXXXXXXXXXXX and the last offset

O1 is blank. The desired out come should be: XOXXXOXXXXXOXX (with the last offset blank in this example.



Sub Testx()

Dim J As String

Dim RangerTest As Range, Cell As Range

J = Range("A9").Value



For Each Cell In Range("RangerTest")

If Cell.Value = J Then Cell.Offset(5, 0).Value = "O"

If Cell.Value <> J Then Cell.Offset(5, 0).Value = "X"

If Cell.Value = "" Then Cell.Offset(5, 0).Value = ""

Next



End Sub



Can't figure where I am going wrong???



Regards

Howard

Option Explicit
Option Compare Text
Sub TheTestSas()
Dim J As String
Dim RANGERTEST As Range
Dim C As Range
Application.ScreenUpdating = False
J = Range("A10").Value
Range("RANGERTEST").Offset(8).Value = ""
For Each C In Range("RANGERTEST")
If Len(Application.Trim(C)) > 0 Then
Select Case C
Case Is = J: C.Offset(8) = "O"
Case Is <> J: C.Offset(8) = "X"
End Select
End If
Next
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top