Another code optimization needed to boast performance

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
This code is taking a bit longer time to run. I want to run all processes in memory before placing result to worksheet.

I took the inspiration from @DanteAmor solution at:

1. Code optimization required - run all processes in memory before placing result to worksheet

2. Load part of data to memory, perform some calculations and rank then show alert with message box -vba


Code:
                    For i = 1 To 10
                        For Each cel In .Range("R7:R" & lr).Offset(, i - 1)
                            Select Case .Cells(cel.Row, "C")
                                Case "Z " & 1 To "Z " & 3
                                    Select Case cel.Value
                                        Case Is >= 83: cel = 1
                                        Case Is >= 76: cel = 2
                                        Case Is >= 69: cel = 3
                                        Case Is >= 60: cel = 4
                                        Case Is >= 50: cel = 5
                                        Case Is >= 40: cel = 6
                                        Case Is >= 30: cel = 7
                                        Case Is >= 20: cel = 8
                                        Case Is >= 1:  cel = 9
                                    End Select
                                Case Else
                                   Select Case cel.Value
                                        Case Is >= 80: cel = 1
                                        Case Is >= 75: cel = 2
                                        Case Is >= 70: cel = 3
                                        Case Is >= 65: cel = 4
                                        Case Is >= 1:  cel = 5
                                    End Select
                            End Select
                        Next cel
                    Next i

Thanks in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Can you post all of the code? Also, if you post an example of what your data looks like vs. the results your trying to get, that would be helpful.
 
Upvote 0
Try this:

VBA Code:
Sub test()
  Dim sh As Worksheet, a As Variant, b As Variant, i As Long, j As Long, k As Long
  
  Set sh = Sheets("DATA")
  a = sh.Range("C7:AA" & sh.Range("C" & Rows.Count).End(3).Row).Value2
  ReDim b(1 To UBound(a, 1), 1 To 10)
  
  For i = 1 To UBound(a, 1)   'column C fila 7
    For j = 16 To 25          'columns R to AA
      k = j - 15
      Select Case a(i, 1)
        Case "Z " & 1 To "Z " & 3
          Select Case a(i, j)
            Case Is >= 83: b(i, k) = 1
            Case Is >= 76: b(i, k) = 2
            Case Is >= 69: b(i, k) = 3
            Case Is >= 60: b(i, k) = 4
            Case Is >= 50: b(i, k) = 5
            Case Is >= 40: b(i, k) = 6
            Case Is >= 30: b(i, k) = 7
            Case Is >= 20: b(i, k) = 8
            Case Is >= 1:  b(i, k) = 9
          End Select
        Case Else
          Select Case a(i, j)
            Case Is >= 80: b(i, k) = 1
            Case Is >= 75: b(i, k) = 2
            Case Is >= 70: b(i, k) = 3
            Case Is >= 65: b(i, k) = 4
            Case Is >= 1:  b(i, k) = 5
          End Select
      End Select
    Next j
  Next i
  Range("R7").Resize(UBound(b, 1), UBound(b, 2)).Value = b
End Sub
 
Upvote 0
Can you post all of the code? Also, if you post an example of what your data looks like vs. the results your trying to get, that would be helpful.
Oops. Sorry for not giving out explicit info. Will work on that afterwards .
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top