0

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 

1 Answer 1

1

This line

min = Sheets("Tube OD").Cells(4 + m, 26 + n) And col = n 

should be two lines

min = Sheets("Tube OD").Cells(4 + m, 26 + n) col = n 

otherwise what actually happens is you set min to a boolean value that checks if these two statements are both true:

Sheets("Tube OD").Cells(4 + m, 26 + n) col = n 

It seems they're not, so min = False and that's a value of zero :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.