Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90189

Multiple loops in VBA are slow [duplicate]

$
0
0

I am relatively new to VBA. I have made a tool for cleaning my cross references.

The way it works, it that i have the complete raw list which i loop through to delete rows where a certain condition is met.

Example:

'RACKS LOOP
'if checkbox is checked
If Sheet1.CheckBox14.Value = True Then

'loop
 Dim rngRK As Range
 Dim iRK As Integer, counterRK As Integer

 'Set the range to evaluate to rngRK.
 Set rngRK = Range("D1:D32000")

 'initialize iRK to 1
 iRK = 1

 For counterRK = 1 To rngRK.Rows.Count

      'If cell i in the range contains the value: "RACKS",
       'delete the row.
        If rngRK.Cells(iRK) = "RACKS" Then
            rngRK.Cells(iRK).EntireRow.Delete
        Else
        'Else increment i
            iRK = iRK + 1
        End If

 Next
'end loop
Else
End If

I have 30 loops like the above in this file, as i have many different conditions i need to be able to choose from. The only issue is that i think it takes a lot of time to process.

Is there any smarter/faster way to do this?


Viewing all articles
Browse latest Browse all 90189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>