Can someone help me clarify if this is the best practice, or just extra programming.
To me it seems best to place use a variable to hold the value from a worksheet that is going to be picked up multiple times during run time.
Ie. If I have this code which I created that will tell me the widest column width for a certain column range:
endRange = Range("D6").End(xlToRight).Cells.Column
For x = 4 To endRange
holdWidth = Cells(7, x).ColumnWidth
If holdWidth > largestWidth Then
For y = 4 To endRange
If holdWidth < Cells(7, y).ColumnWidth Then
holdWidth = Cells(7, y).ColumnWidth
largestWidth = Cells(7, y).ColumnWidth
End If
Next y
End If
Next x
I can then use largestWidth for the rest of my procedure
My question is: Do you think it is best practice to assign "Range("D6").End(xlToRight).Cells.Column" to the variable "endRange" and then use that variable in my For loops, or is that just overkill...it seems to me like that should be faster overall.
Any thoughts would be appreciated.
Thanks,
Rees
To me it seems best to place use a variable to hold the value from a worksheet that is going to be picked up multiple times during run time.
Ie. If I have this code which I created that will tell me the widest column width for a certain column range:
endRange = Range("D6").End(xlToRight).Cells.Column
For x = 4 To endRange
holdWidth = Cells(7, x).ColumnWidth
If holdWidth > largestWidth Then
For y = 4 To endRange
If holdWidth < Cells(7, y).ColumnWidth Then
holdWidth = Cells(7, y).ColumnWidth
largestWidth = Cells(7, y).ColumnWidth
End If
Next y
End If
Next x
I can then use largestWidth for the rest of my procedure
My question is: Do you think it is best practice to assign "Range("D6").End(xlToRight).Cells.Column" to the variable "endRange" and then use that variable in my For loops, or is that just overkill...it seems to me like that should be faster overall.
Any thoughts would be appreciated.
Thanks,
Rees