Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Get rid of "False" from an array

0
  I used excel 2019 (No VBA).

The array {1;FALSE;3;FALSE;FALSE;6;FALSE;FALSE;FALSE;10;FALSE;FALSE;13;FALSE;FALSE;FALSE} is the result of the equation:
ROW(INDIRECT("1:"&(COUNTA(A2:A17))))*(A2:A17="a") for the column shown in image below. It is to obtain the order numbers of the letter "a" within the rane A2:A17

So, I want to return only the number; meaning to say I need to return the above array to:
{1;3;6;10;13}

Answer
Discuss

Discussion

You can't post an image, but you can edit your question and upload a sample file.
don (rep: 1989) Dec 23, '20 at 3:47 pm
Add to Discussion

Answers

0

I doubt the validity of your formula because the size of the two ranges in your multiplication isn't likely to be the same when you exit laboratory conditions. However, even if that isn't a real problem or it can be overcome the result of that test must include False values which can't be removed. Please try the formula below instead.

=FILTER(Data,ISNUMBER(Data))

Data is a named range that I used for the purpose of transparency. In my test it was set to A2:A17. You can either name the range you are examining as I did or repalce the name in the formula with the range address, like, =FILTER($A$2:$A$17,ISNUMBER($A$2:$A$17))

Edit:-  =================================

If you don't have Excel 365 and must therefore do without the FILTER function, hopefully the function below will help. I have no way of testing but I believe all functions used in the formula are of older vintage.

=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW(Data)/(ISNUMBER(Data)),ROW(1:1))),"")

Paste this formula in a cell in row 2 or lower and copy down for as far as it returns a value. The Data range can be replaced with ard cell references as explained above. In this context please note that A:A must specify the column in which Data is located.

Discuss

Discussion

  Thank you for the swift response,
Using Filter is really in mind from the begining. Unfortunately this function (FILTER) is not availble in 2019 version I am using it is only in 365 version.
Regards  
makihussain Dec 24, '20 at 3:54 am
@Variatus- Good answer but FILTER isn't available in versions other than Offfice 365 sadly. Have a great Christmas anyway!

@Maki - I can't think how to do this without VBA (can't use the Office 365 FILTER or TEXTJOIN functions which are not not available to 2019 and 2016 users). Note that the tutorial Excel Formula to Remove ALL Special Characters implies that CONCAT (or CONCATENATE) can be used in an array formula (in the tutorial's" Pre-Excel 365 Version") but I've never got it to work in an array formula.

Why don't you want to use VBA for this? A user-defined function could do what you want  I believe.
John_Ru (rep: 6142) Dec 24, '20 at 6:02 am
Maki Hussain, Sorry about that. I didn't realise how recent the FILTER function was. I have edited my answer to include a solution using the AGGREGATE function instead.
Variatus (rep: 4889) Dec 24, '20 at 7:10 am
Add to Discussion
0

Maki

Please find attached a file with a User Defined Function (UDF) to do what I think you want. This follows my discussion point (in the answer from @Variatus).

The UDF is entered in the spreadsheet like this (see cell C2 in yellow):

=ArrayTest(A2:A17,"a",1)

...where ArrayTest is the name of the UDF with parameters:

  • A2:A17 is the range you want to search,
  • "a" is what to search for (needs inverted commas if text but a number can be entered without, e.g.6). These two parameters alone would produce the row numbers of the searched value BUT...
  • the 1 is an optional input (lessRow in the VBA) if you want the result to be relative to a starting row- it must be an integer (like a row number) and gets subtracted from the row position (so I entered 1 to make row 2= position 1 as your question implied).

The output of the UDF is a text string in the cell like 'a' in positions 1; 3; 6; 10; 13;.

The VBA code for the UDF is just this (in Module 1):

Function ArrayTest(ByVal aRange As Range, aTest As Variant, lessRow As Integer)

For Each aCell In aRange
    If aCell.Value = aTest Then ArrayTest = ArrayTest & (aCell.Row - lessRow) & "; "
Next aCell

ArrayTest = "'" & aTest & "' in positions " & ArrayTest

End Function
Discuss

Discussion

Maki.
Oops, just read the answer revision from @Variatus (but couldn't get it to work in very limited time) and realise you're looking for an array as an output.

This array formula leaves blanks (rather than false) in the array:
{=IF(A2:A17="a",ROW(A2:A17)-1,"")}
.

Sorry, have no more time to play with this. Good luck.
John_Ru (rep: 6142) Dec 24, '20 at 8:46 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login