excel array formula for divisibility2019 Community Moderator ElectionHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How to create strings containing double quotes in Excel formulas?Excel formula to reference 'CELL TO THE LEFT'Return empty cell from formula in ExcelShortcut to Apply a Formula to an Entire Column in ExcelMinimum of Excel Array Formula with INDEX()Prevent cell numbers from incrementing in a formula in ExcelExcel Array formula with IF statementExcel Array Formula AssistanceExcel formula doesn't work
2D counterpart of std::array in C++17
Identifying the interval from A♭ to D♯
How could a scammer know the apps on my phone / iTunes account?
Humanity loses the vast majority of its technology, information, and population in the year 2122. How long does it take to rebuild itself?
My adviser wants to be the first author
What has been your most complicated TikZ drawing?
Do I need life insurance if I can cover my own funeral costs?
Why do Australian milk farmers need to protest supermarkets' milk price?
Employee lack of ownership
My story is written in English, but is set in my home country. What language should I use for the dialogue?
Schematic conventions for different supply rails
Citation at the bottom for subfigures in beamer frame
Can the damage from a Talisman of Pure Good (or Ultimate Evil) be non-lethal?
Informing my boss about remarks from a nasty colleague
How to make healing in an exploration game interesting
Is Mortgage interest accrued after a December payment tax deductible?
Check this translation of Amores 1.3.26
At what level can a dragon innately cast its spells?
Why must traveling waves have the same amplitude to form a standing wave?
Good allowance savings plan?
Rules about breaking the rules. How do I do it well?
How to generate globally unique ids for different tables of the same database?
Counting certain elements in lists
Can elves maintain concentration in a trance?
excel array formula for divisibility
2019 Community Moderator ElectionHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How to create strings containing double quotes in Excel formulas?Excel formula to reference 'CELL TO THE LEFT'Return empty cell from formula in ExcelShortcut to Apply a Formula to an Entire Column in ExcelMinimum of Excel Array Formula with INDEX()Prevent cell numbers from incrementing in a formula in ExcelExcel Array formula with IF statementExcel Array Formula AssistanceExcel formula doesn't work
Can there be a single formula (maybe an array formula) which can indicate whether the number in F1 is divisible by any of the numbers in the cells (A1:D9)?

Regards.
excel excel-formula
add a comment |
Can there be a single formula (maybe an array formula) which can indicate whether the number in F1 is divisible by any of the numbers in the cells (A1:D9)?

Regards.
excel excel-formula
add a comment |
Can there be a single formula (maybe an array formula) which can indicate whether the number in F1 is divisible by any of the numbers in the cells (A1:D9)?

Regards.
excel excel-formula
Can there be a single formula (maybe an array formula) which can indicate whether the number in F1 is divisible by any of the numbers in the cells (A1:D9)?

Regards.
excel excel-formula
excel excel-formula
asked Mar 6 at 18:44
babsdocbabsdoc
3072513
3072513
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Something like:
=MIN(MOD(F1, A1:D9))
will be 0 if any of the numbers is a factor.
Thanks @Tim. This is elegant. I was missing out on combining the mod function with the Min, its very clever actually. Thanks.
– babsdoc
Mar 6 at 19:11
add a comment |
Try the following small user defined function:
Public Function IsDivisible(rng As Range, v As Long) As Boolean
Dim r As Range
IsDivisible = False
For Each r In rng
If v Mod r.Value = 0 Then
IsDivisible = True
Exit Function
End If
Next r
End Function
For example:

User Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I
ALT-M opens a fresh module - paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=myfunction(A1)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
Thanks @Gary's Student. This helps me for now, but I would like to know if its possible to be done without VBA, like an inbuilt function. Thank you for your attention though, it means a lot.
– babsdoc
Mar 6 at 18:58
1. Could you explain the practical use of Public in this case i.e. in standard module. 2. When I'm assuming that IsDivisible = False is here only to make a point and it is by default False, is there a case when I could be wrong?
– VBasic2008
Mar 6 at 19:04
@VBasic2008 you are correct on both points.
– Gary's Student
Mar 6 at 19:12
add a comment |
SUMPRODUCT 'Deals' in Arrays
Again, credits to Tim Williams for his brilliant response and for simply 'forcing' me to investigate this matter further.
Formulas
You can use this formula:
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0)),TRUE,FALSE)
which derived from the formula that counts the number of occurrences of zero remainders:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0))
which brings us to the reason why I would investigate further.
I wanted to exclude 1 and the value in F1, 81, from the occurrences count i.e. if the only zero occurrence is number 1 or 81, a formula would show FALSE, which the following two formulas do:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1))
which counts the number of occurrences of zero remainders after dividing the value in F1 with each value in range A1:D9, but not counting if 1 or the value in F1 where being divided and
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1)),TRUE,FALSE)
which returns TRUE if such an occurrence is found, or FALSE if not.
Workbook
Workbook Download (Dropbox)
So I played 'a little' in a worksheet to learn a lot.

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%2f55030138%2fexcel-array-formula-for-divisibility%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Something like:
=MIN(MOD(F1, A1:D9))
will be 0 if any of the numbers is a factor.
Thanks @Tim. This is elegant. I was missing out on combining the mod function with the Min, its very clever actually. Thanks.
– babsdoc
Mar 6 at 19:11
add a comment |
Something like:
=MIN(MOD(F1, A1:D9))
will be 0 if any of the numbers is a factor.
Thanks @Tim. This is elegant. I was missing out on combining the mod function with the Min, its very clever actually. Thanks.
– babsdoc
Mar 6 at 19:11
add a comment |
Something like:
=MIN(MOD(F1, A1:D9))
will be 0 if any of the numbers is a factor.
Something like:
=MIN(MOD(F1, A1:D9))
will be 0 if any of the numbers is a factor.
answered Mar 6 at 19:05
Tim WilliamsTim Williams
88.3k97087
88.3k97087
Thanks @Tim. This is elegant. I was missing out on combining the mod function with the Min, its very clever actually. Thanks.
– babsdoc
Mar 6 at 19:11
add a comment |
Thanks @Tim. This is elegant. I was missing out on combining the mod function with the Min, its very clever actually. Thanks.
– babsdoc
Mar 6 at 19:11
Thanks @Tim. This is elegant. I was missing out on combining the mod function with the Min, its very clever actually. Thanks.
– babsdoc
Mar 6 at 19:11
Thanks @Tim. This is elegant. I was missing out on combining the mod function with the Min, its very clever actually. Thanks.
– babsdoc
Mar 6 at 19:11
add a comment |
Try the following small user defined function:
Public Function IsDivisible(rng As Range, v As Long) As Boolean
Dim r As Range
IsDivisible = False
For Each r In rng
If v Mod r.Value = 0 Then
IsDivisible = True
Exit Function
End If
Next r
End Function
For example:

User Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I
ALT-M opens a fresh module - paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=myfunction(A1)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
Thanks @Gary's Student. This helps me for now, but I would like to know if its possible to be done without VBA, like an inbuilt function. Thank you for your attention though, it means a lot.
– babsdoc
Mar 6 at 18:58
1. Could you explain the practical use of Public in this case i.e. in standard module. 2. When I'm assuming that IsDivisible = False is here only to make a point and it is by default False, is there a case when I could be wrong?
– VBasic2008
Mar 6 at 19:04
@VBasic2008 you are correct on both points.
– Gary's Student
Mar 6 at 19:12
add a comment |
Try the following small user defined function:
Public Function IsDivisible(rng As Range, v As Long) As Boolean
Dim r As Range
IsDivisible = False
For Each r In rng
If v Mod r.Value = 0 Then
IsDivisible = True
Exit Function
End If
Next r
End Function
For example:

User Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I
ALT-M opens a fresh module - paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=myfunction(A1)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
Thanks @Gary's Student. This helps me for now, but I would like to know if its possible to be done without VBA, like an inbuilt function. Thank you for your attention though, it means a lot.
– babsdoc
Mar 6 at 18:58
1. Could you explain the practical use of Public in this case i.e. in standard module. 2. When I'm assuming that IsDivisible = False is here only to make a point and it is by default False, is there a case when I could be wrong?
– VBasic2008
Mar 6 at 19:04
@VBasic2008 you are correct on both points.
– Gary's Student
Mar 6 at 19:12
add a comment |
Try the following small user defined function:
Public Function IsDivisible(rng As Range, v As Long) As Boolean
Dim r As Range
IsDivisible = False
For Each r In rng
If v Mod r.Value = 0 Then
IsDivisible = True
Exit Function
End If
Next r
End Function
For example:

User Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I
ALT-M opens a fresh module - paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=myfunction(A1)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
Try the following small user defined function:
Public Function IsDivisible(rng As Range, v As Long) As Boolean
Dim r As Range
IsDivisible = False
For Each r In rng
If v Mod r.Value = 0 Then
IsDivisible = True
Exit Function
End If
Next r
End Function
For example:

User Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I
ALT-M opens a fresh module - paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=myfunction(A1)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
answered Mar 6 at 18:53
Gary's StudentGary's Student
74.4k94064
74.4k94064
Thanks @Gary's Student. This helps me for now, but I would like to know if its possible to be done without VBA, like an inbuilt function. Thank you for your attention though, it means a lot.
– babsdoc
Mar 6 at 18:58
1. Could you explain the practical use of Public in this case i.e. in standard module. 2. When I'm assuming that IsDivisible = False is here only to make a point and it is by default False, is there a case when I could be wrong?
– VBasic2008
Mar 6 at 19:04
@VBasic2008 you are correct on both points.
– Gary's Student
Mar 6 at 19:12
add a comment |
Thanks @Gary's Student. This helps me for now, but I would like to know if its possible to be done without VBA, like an inbuilt function. Thank you for your attention though, it means a lot.
– babsdoc
Mar 6 at 18:58
1. Could you explain the practical use of Public in this case i.e. in standard module. 2. When I'm assuming that IsDivisible = False is here only to make a point and it is by default False, is there a case when I could be wrong?
– VBasic2008
Mar 6 at 19:04
@VBasic2008 you are correct on both points.
– Gary's Student
Mar 6 at 19:12
Thanks @Gary's Student. This helps me for now, but I would like to know if its possible to be done without VBA, like an inbuilt function. Thank you for your attention though, it means a lot.
– babsdoc
Mar 6 at 18:58
Thanks @Gary's Student. This helps me for now, but I would like to know if its possible to be done without VBA, like an inbuilt function. Thank you for your attention though, it means a lot.
– babsdoc
Mar 6 at 18:58
1. Could you explain the practical use of Public in this case i.e. in standard module. 2. When I'm assuming that IsDivisible = False is here only to make a point and it is by default False, is there a case when I could be wrong?
– VBasic2008
Mar 6 at 19:04
1. Could you explain the practical use of Public in this case i.e. in standard module. 2. When I'm assuming that IsDivisible = False is here only to make a point and it is by default False, is there a case when I could be wrong?
– VBasic2008
Mar 6 at 19:04
@VBasic2008 you are correct on both points.
– Gary's Student
Mar 6 at 19:12
@VBasic2008 you are correct on both points.
– Gary's Student
Mar 6 at 19:12
add a comment |
SUMPRODUCT 'Deals' in Arrays
Again, credits to Tim Williams for his brilliant response and for simply 'forcing' me to investigate this matter further.
Formulas
You can use this formula:
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0)),TRUE,FALSE)
which derived from the formula that counts the number of occurrences of zero remainders:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0))
which brings us to the reason why I would investigate further.
I wanted to exclude 1 and the value in F1, 81, from the occurrences count i.e. if the only zero occurrence is number 1 or 81, a formula would show FALSE, which the following two formulas do:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1))
which counts the number of occurrences of zero remainders after dividing the value in F1 with each value in range A1:D9, but not counting if 1 or the value in F1 where being divided and
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1)),TRUE,FALSE)
which returns TRUE if such an occurrence is found, or FALSE if not.
Workbook
Workbook Download (Dropbox)
So I played 'a little' in a worksheet to learn a lot.

add a comment |
SUMPRODUCT 'Deals' in Arrays
Again, credits to Tim Williams for his brilliant response and for simply 'forcing' me to investigate this matter further.
Formulas
You can use this formula:
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0)),TRUE,FALSE)
which derived from the formula that counts the number of occurrences of zero remainders:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0))
which brings us to the reason why I would investigate further.
I wanted to exclude 1 and the value in F1, 81, from the occurrences count i.e. if the only zero occurrence is number 1 or 81, a formula would show FALSE, which the following two formulas do:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1))
which counts the number of occurrences of zero remainders after dividing the value in F1 with each value in range A1:D9, but not counting if 1 or the value in F1 where being divided and
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1)),TRUE,FALSE)
which returns TRUE if such an occurrence is found, or FALSE if not.
Workbook
Workbook Download (Dropbox)
So I played 'a little' in a worksheet to learn a lot.

add a comment |
SUMPRODUCT 'Deals' in Arrays
Again, credits to Tim Williams for his brilliant response and for simply 'forcing' me to investigate this matter further.
Formulas
You can use this formula:
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0)),TRUE,FALSE)
which derived from the formula that counts the number of occurrences of zero remainders:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0))
which brings us to the reason why I would investigate further.
I wanted to exclude 1 and the value in F1, 81, from the occurrences count i.e. if the only zero occurrence is number 1 or 81, a formula would show FALSE, which the following two formulas do:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1))
which counts the number of occurrences of zero remainders after dividing the value in F1 with each value in range A1:D9, but not counting if 1 or the value in F1 where being divided and
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1)),TRUE,FALSE)
which returns TRUE if such an occurrence is found, or FALSE if not.
Workbook
Workbook Download (Dropbox)
So I played 'a little' in a worksheet to learn a lot.

SUMPRODUCT 'Deals' in Arrays
Again, credits to Tim Williams for his brilliant response and for simply 'forcing' me to investigate this matter further.
Formulas
You can use this formula:
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0)),TRUE,FALSE)
which derived from the formula that counts the number of occurrences of zero remainders:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0))
which brings us to the reason why I would investigate further.
I wanted to exclude 1 and the value in F1, 81, from the occurrences count i.e. if the only zero occurrence is number 1 or 81, a formula would show FALSE, which the following two formulas do:
=SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1))
which counts the number of occurrences of zero remainders after dividing the value in F1 with each value in range A1:D9, but not counting if 1 or the value in F1 where being divided and
=IF(SUMPRODUCT(--(MOD(F$1,$A$1:$D$9)=0),--($A$1:$D$9>1),--($A$1:$D$9<$F$1)),TRUE,FALSE)
which returns TRUE if such an occurrence is found, or FALSE if not.
Workbook
Workbook Download (Dropbox)
So I played 'a little' in a worksheet to learn a lot.

answered Mar 7 at 1:46
VBasic2008VBasic2008
3,2762417
3,2762417
add a comment |
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.
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%2f55030138%2fexcel-array-formula-for-divisibility%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