I have a excel VBA macro which is to be used to calculate the size of a machined part. The first part of the macro is set up to obtain values from a worksheet and calculates an area based on some predefined options and prints them to excel. The second part is where I have some issues.
I have converted the table to a 2D array (save processing time) and started to fill in the array via 2 loops, 1 controls the row, 1 the column. Within the loop I am trying to find the minimum none zero value and the associated column, this then helps with the final part of the macro which works. I have also set the min number to be a large value which will never be exceeded.
When I run the macro step by step the first none zero value I come across resets the min value to zero and does not change the column number. Can anyone guide me as to where I have gone wrong?
maxtubesel = Sheets("Tube OD").Cells(Rows.Count, "R").End(xlUp).Row - 4 'Find min and col value in array Dim resarray() As Long ReDim resarray(maxtubesel, 5) min = 1000000 col = 0 For m = 0 To 2 ' maxtubesel For n = 0 To 4 resarray(m, n) = Sheets("Tube OD").Cells(4 + m, 26 + n) If Sheets("Tube OD").Cells(4 + m, 26 + n) <> "" Or Sheets("Tube OD").Cells(4 + m, 26 + n) <> 0 Then min = Sheets("Tube OD").Cells(4 + m, 26 + n) And col = n End If Next n Next m