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!
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