deleting rows --> excel not responding

littlerascal

New Member
Joined
Oct 10, 2015
Messages
3
Dear readers

The following code is creating a string of the following format "1:1, 5:5, 45:45, ..." in order to create a range with specified rows and then delete it in multiple sheets. On the second last line excel hangs and shows "Not responding" after about 10 seconds.

As you can see, it's 19 rows, so not that much. Also I use pretty much the same code in a different module for the same sheets with significantly more rows, there it works flawlessly.

The range is set correct; I changed said line to r.select and set a breakpoint a line below, checked the file and the right rows were selected. When I tried to delete it manually excel stopped responding as well.

Any idea what might be the issue?

Thanks for any response!

Code:
Dim s As String, r As range, item As Variant, rows() As Variant, n As Integer, sheetsArray As Variant

sheetsArray = Array("market data input", "manager input", "Comp plan")

'sort all sheets in initials column
For Each item In sheetsArray
    With ThisWorkbook.Sheets(item)
        If .AutoFilterMode Then
            .AutoFilter.sort.SortFields.Clear
        End If
        .range("tbl" & Replace(item, " ", "")).sort key1:="Initials", order1:=xlAscending, Header:=xlYes
    End With
Next item


ReDim rows(0 To 18)


'fills array with rows references
For Each item In Sheet10.range("dele")
    rows(n) = item.value & ":" & item.value
    n = n + 1
Next item


'create string which looks like "12:12, 34:34, ..."
s = Join(rows, ",")


'delete rows in every sheet
For Each item In sheetsArray
    Set r = ThisWorkbook.Sheets(item).range(s)
    r.delete
Next item
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,216,750
Messages
6,132,506
Members
449,730
Latest member
SeanHT

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