0

So, whenever I am running this code, it is always going into the else block, even if there isn't any data in the array

    If IsEmpty(arr) Then 'want to check if the array is not empty
    Exit Sub
    Else
    statements.....
    endif
braX
  • 11,506
  • 5
  • 20
  • 33
  • Take a look in this answer: https://stackoverflow.com/a/56544936/7658533 – AHeyne Apr 13 '20 at 10:50
  • I've used Not Not arr in my code, but then also it is going into if block even though my array doesn't have any values in it – srikanth v Apr 13 '20 at 16:14
  • I explicitly linked to a specific answer. This does not use the `not not` syntax. – AHeyne Apr 13 '20 at 16:17
  • Hey thank you for trying to help me, I am a beginner in vba, but on a macro, I am not understanding what you sent, could you help me with a code, that solve this problem – srikanth v Apr 13 '20 at 16:20
  • I want to execute few statements, when the array is not empty, so first i have used isempty(arr) function, but it always going into the else block, even if there is data or there isn't any data. – srikanth v Apr 13 '20 at 16:22
  • You need to copy the function `IsArrayAllocated` in your module and then use it like `If not IsArrayAllocated(arr) Then`. – AHeyne Apr 13 '20 at 16:23
  • tried using IsArrayAllocated function, no luck, it is again printing statements in both the cases, when there is data in the array and when the array is empty – srikanth v Apr 13 '20 at 16:36
  • What returns `IsArray(arr)`? Is `arr` even an array? – AHeyne Apr 13 '20 at 16:48
  • I tried this Debug.Print IsArray(arr) and it is printing true and my array name is arr – srikanth v Apr 13 '20 at 16:54
  • What about `Debug.Print LBound(arr)` and `Debug.Print UBound(arr)`? What do they return? – AHeyne Apr 13 '20 at 16:56
  • Debug.Print LBound(arr) is 1, Debug.Print UBound(arr) is 4, but IsArray(arr) is returning true for both the cases like when there are values in the array and when there are not any values (Empty) in the array – srikanth v Apr 13 '20 at 17:02
  • Your array **is not empty**, because **it has elements** and so is initialized. If there are values inside the arrays elements is something different! – AHeyne Apr 13 '20 at 17:08
  • You need to understand this basics. Read this, there are some explanations and helper functions. – AHeyne Apr 13 '20 at 17:14
  • I was looping through the cells in 4 rows and 2 columns and putting those values in the array, but in my data, there are some cells where in those 4 rows and 2 columns are blank, so how should i get rid off those blank cells, I just want to execute statements when I have values in my array – srikanth v Apr 13 '20 at 17:14
  • Thank you for trying to help me @unhandled Exception, unfortunately i got stuck – srikanth v Apr 13 '20 at 19:18
  • You should open a new question and there post your relevant code. Here it’s not possible without your code. – AHeyne Apr 13 '20 at 19:21

0 Answers0