How to compare value with other values in range easily
up vote
0
down vote
favorite
could someone help, how to rewrite folowing condition somehow smarter (and definitely shorter)?
It should pretty much say: If value in one specific cell is not empty and at the same time is different from any value in cells from X32 to X47 → do something
Thanks a lot!
For i = 4 To 69
If Range(SO_COLUMN & i) <> "" _
And Range(SO_COLUMN & i) <> Range("X32") And Range(SO_COLUMN & i) <> Range("X33") And Range(SO_COLUMN & i) <> Range("X34") And Range(SO_COLUMN & i) <> Range("X35") _
And Range(SO_COLUMN & i) <> Range("X36") And Range(SO_COLUMN & i) <> Range("X37") And Range(SO_COLUMN & i) <> Range("X38") And Range(SO_COLUMN & i) <> Range("X39") _
And Range(SO_COLUMN & i) <> Range("X40") And Range(SO_COLUMN & i) <> Range("X41") And Range(SO_COLUMN & i) <> Range("X42") And Range(SO_COLUMN & i) <> Range("X43") _
And Range(SO_COLUMN & i) <> Range("X44") And Range(SO_COLUMN & i) <> Range("X45") And Range(SO_COLUMN & i) <> Range("X46") And Range(SO_COLUMN & i) <> Range("X47") Then
"DO SOMETHING"
End If
Next i
excel vba
add a comment |
up vote
0
down vote
favorite
could someone help, how to rewrite folowing condition somehow smarter (and definitely shorter)?
It should pretty much say: If value in one specific cell is not empty and at the same time is different from any value in cells from X32 to X47 → do something
Thanks a lot!
For i = 4 To 69
If Range(SO_COLUMN & i) <> "" _
And Range(SO_COLUMN & i) <> Range("X32") And Range(SO_COLUMN & i) <> Range("X33") And Range(SO_COLUMN & i) <> Range("X34") And Range(SO_COLUMN & i) <> Range("X35") _
And Range(SO_COLUMN & i) <> Range("X36") And Range(SO_COLUMN & i) <> Range("X37") And Range(SO_COLUMN & i) <> Range("X38") And Range(SO_COLUMN & i) <> Range("X39") _
And Range(SO_COLUMN & i) <> Range("X40") And Range(SO_COLUMN & i) <> Range("X41") And Range(SO_COLUMN & i) <> Range("X42") And Range(SO_COLUMN & i) <> Range("X43") _
And Range(SO_COLUMN & i) <> Range("X44") And Range(SO_COLUMN & i) <> Range("X45") And Range(SO_COLUMN & i) <> Range("X46") And Range(SO_COLUMN & i) <> Range("X47") Then
"DO SOMETHING"
End If
Next i
excel vba
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
could someone help, how to rewrite folowing condition somehow smarter (and definitely shorter)?
It should pretty much say: If value in one specific cell is not empty and at the same time is different from any value in cells from X32 to X47 → do something
Thanks a lot!
For i = 4 To 69
If Range(SO_COLUMN & i) <> "" _
And Range(SO_COLUMN & i) <> Range("X32") And Range(SO_COLUMN & i) <> Range("X33") And Range(SO_COLUMN & i) <> Range("X34") And Range(SO_COLUMN & i) <> Range("X35") _
And Range(SO_COLUMN & i) <> Range("X36") And Range(SO_COLUMN & i) <> Range("X37") And Range(SO_COLUMN & i) <> Range("X38") And Range(SO_COLUMN & i) <> Range("X39") _
And Range(SO_COLUMN & i) <> Range("X40") And Range(SO_COLUMN & i) <> Range("X41") And Range(SO_COLUMN & i) <> Range("X42") And Range(SO_COLUMN & i) <> Range("X43") _
And Range(SO_COLUMN & i) <> Range("X44") And Range(SO_COLUMN & i) <> Range("X45") And Range(SO_COLUMN & i) <> Range("X46") And Range(SO_COLUMN & i) <> Range("X47") Then
"DO SOMETHING"
End If
Next i
excel vba
could someone help, how to rewrite folowing condition somehow smarter (and definitely shorter)?
It should pretty much say: If value in one specific cell is not empty and at the same time is different from any value in cells from X32 to X47 → do something
Thanks a lot!
For i = 4 To 69
If Range(SO_COLUMN & i) <> "" _
And Range(SO_COLUMN & i) <> Range("X32") And Range(SO_COLUMN & i) <> Range("X33") And Range(SO_COLUMN & i) <> Range("X34") And Range(SO_COLUMN & i) <> Range("X35") _
And Range(SO_COLUMN & i) <> Range("X36") And Range(SO_COLUMN & i) <> Range("X37") And Range(SO_COLUMN & i) <> Range("X38") And Range(SO_COLUMN & i) <> Range("X39") _
And Range(SO_COLUMN & i) <> Range("X40") And Range(SO_COLUMN & i) <> Range("X41") And Range(SO_COLUMN & i) <> Range("X42") And Range(SO_COLUMN & i) <> Range("X43") _
And Range(SO_COLUMN & i) <> Range("X44") And Range(SO_COLUMN & i) <> Range("X45") And Range(SO_COLUMN & i) <> Range("X46") And Range(SO_COLUMN & i) <> Range("X47") Then
"DO SOMETHING"
End If
Next i
excel vba
excel vba
asked Nov 11 at 5:51
Vratislav Vašina
124
124
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Maybe something like:
With ThisWorkbook.Worksheets("yourSheetName")
For i = 4 To 69
If Not IsEmpty(.Range(SO_COLUMN & i)) And IsError(Application.Match(.Range(SO_COLUMN & i), .Range("X32:X47"), 0)) Then
'do something
End If
Next
End With
2
Well said. And good job for almost hitting 25k!!! :D
– K.Dᴀᴠɪs
Nov 11 at 6:18
@K.Dᴀᴠɪs That is kind. Thank you.
– QHarr
Nov 11 at 6:19
The "IsEmpty" part does not work, so i replaced it with original Range(SO_COLUMN & i) <> "" and the rest works perfectly. Thank you very much :)
– Vratislav Vašina
Nov 11 at 7:45
you are welcome. Do you perhaps have formulas in the cells? You can use <> vbNullString for faster comparisons than "".
– QHarr
Nov 11 at 7:46
1
You are perfectly right, I do have formulas in there. I adjust as you recomend and it works smoothly :) Thank you again.
– Vratislav Vašina
Nov 11 at 7:56
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Maybe something like:
With ThisWorkbook.Worksheets("yourSheetName")
For i = 4 To 69
If Not IsEmpty(.Range(SO_COLUMN & i)) And IsError(Application.Match(.Range(SO_COLUMN & i), .Range("X32:X47"), 0)) Then
'do something
End If
Next
End With
2
Well said. And good job for almost hitting 25k!!! :D
– K.Dᴀᴠɪs
Nov 11 at 6:18
@K.Dᴀᴠɪs That is kind. Thank you.
– QHarr
Nov 11 at 6:19
The "IsEmpty" part does not work, so i replaced it with original Range(SO_COLUMN & i) <> "" and the rest works perfectly. Thank you very much :)
– Vratislav Vašina
Nov 11 at 7:45
you are welcome. Do you perhaps have formulas in the cells? You can use <> vbNullString for faster comparisons than "".
– QHarr
Nov 11 at 7:46
1
You are perfectly right, I do have formulas in there. I adjust as you recomend and it works smoothly :) Thank you again.
– Vratislav Vašina
Nov 11 at 7:56
add a comment |
up vote
2
down vote
accepted
Maybe something like:
With ThisWorkbook.Worksheets("yourSheetName")
For i = 4 To 69
If Not IsEmpty(.Range(SO_COLUMN & i)) And IsError(Application.Match(.Range(SO_COLUMN & i), .Range("X32:X47"), 0)) Then
'do something
End If
Next
End With
2
Well said. And good job for almost hitting 25k!!! :D
– K.Dᴀᴠɪs
Nov 11 at 6:18
@K.Dᴀᴠɪs That is kind. Thank you.
– QHarr
Nov 11 at 6:19
The "IsEmpty" part does not work, so i replaced it with original Range(SO_COLUMN & i) <> "" and the rest works perfectly. Thank you very much :)
– Vratislav Vašina
Nov 11 at 7:45
you are welcome. Do you perhaps have formulas in the cells? You can use <> vbNullString for faster comparisons than "".
– QHarr
Nov 11 at 7:46
1
You are perfectly right, I do have formulas in there. I adjust as you recomend and it works smoothly :) Thank you again.
– Vratislav Vašina
Nov 11 at 7:56
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Maybe something like:
With ThisWorkbook.Worksheets("yourSheetName")
For i = 4 To 69
If Not IsEmpty(.Range(SO_COLUMN & i)) And IsError(Application.Match(.Range(SO_COLUMN & i), .Range("X32:X47"), 0)) Then
'do something
End If
Next
End With
Maybe something like:
With ThisWorkbook.Worksheets("yourSheetName")
For i = 4 To 69
If Not IsEmpty(.Range(SO_COLUMN & i)) And IsError(Application.Match(.Range(SO_COLUMN & i), .Range("X32:X47"), 0)) Then
'do something
End If
Next
End With
answered Nov 11 at 6:16
QHarr
26.9k81839
26.9k81839
2
Well said. And good job for almost hitting 25k!!! :D
– K.Dᴀᴠɪs
Nov 11 at 6:18
@K.Dᴀᴠɪs That is kind. Thank you.
– QHarr
Nov 11 at 6:19
The "IsEmpty" part does not work, so i replaced it with original Range(SO_COLUMN & i) <> "" and the rest works perfectly. Thank you very much :)
– Vratislav Vašina
Nov 11 at 7:45
you are welcome. Do you perhaps have formulas in the cells? You can use <> vbNullString for faster comparisons than "".
– QHarr
Nov 11 at 7:46
1
You are perfectly right, I do have formulas in there. I adjust as you recomend and it works smoothly :) Thank you again.
– Vratislav Vašina
Nov 11 at 7:56
add a comment |
2
Well said. And good job for almost hitting 25k!!! :D
– K.Dᴀᴠɪs
Nov 11 at 6:18
@K.Dᴀᴠɪs That is kind. Thank you.
– QHarr
Nov 11 at 6:19
The "IsEmpty" part does not work, so i replaced it with original Range(SO_COLUMN & i) <> "" and the rest works perfectly. Thank you very much :)
– Vratislav Vašina
Nov 11 at 7:45
you are welcome. Do you perhaps have formulas in the cells? You can use <> vbNullString for faster comparisons than "".
– QHarr
Nov 11 at 7:46
1
You are perfectly right, I do have formulas in there. I adjust as you recomend and it works smoothly :) Thank you again.
– Vratislav Vašina
Nov 11 at 7:56
2
2
Well said. And good job for almost hitting 25k!!! :D
– K.Dᴀᴠɪs
Nov 11 at 6:18
Well said. And good job for almost hitting 25k!!! :D
– K.Dᴀᴠɪs
Nov 11 at 6:18
@K.Dᴀᴠɪs That is kind. Thank you.
– QHarr
Nov 11 at 6:19
@K.Dᴀᴠɪs That is kind. Thank you.
– QHarr
Nov 11 at 6:19
The "IsEmpty" part does not work, so i replaced it with original Range(SO_COLUMN & i) <> "" and the rest works perfectly. Thank you very much :)
– Vratislav Vašina
Nov 11 at 7:45
The "IsEmpty" part does not work, so i replaced it with original Range(SO_COLUMN & i) <> "" and the rest works perfectly. Thank you very much :)
– Vratislav Vašina
Nov 11 at 7:45
you are welcome. Do you perhaps have formulas in the cells? You can use <> vbNullString for faster comparisons than "".
– QHarr
Nov 11 at 7:46
you are welcome. Do you perhaps have formulas in the cells? You can use <> vbNullString for faster comparisons than "".
– QHarr
Nov 11 at 7:46
1
1
You are perfectly right, I do have formulas in there. I adjust as you recomend and it works smoothly :) Thank you again.
– Vratislav Vašina
Nov 11 at 7:56
You are perfectly right, I do have formulas in there. I adjust as you recomend and it works smoothly :) Thank you again.
– Vratislav Vašina
Nov 11 at 7:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246205%2fhow-to-compare-value-with-other-values-in-range-easily%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown