How to compare value with other values in range easily
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 |
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 |
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
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 |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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
29.4k81841
29.4k81841
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