Hey Group,
It has been a while. Hope this is an easy question.
I am now working with very large datasets of almost 50,000 rows and 40+ columns of data per worksheet with a dozen worksheets in the workbook. The data is weather information taken at every minute of the day. Each worksheet is a month of data. I am trying analyze the data but that is taking a tremendous amount of time. Therefore, I am trying to reduce the minute information to an average hourly information.
With some help, I am using the code below (which is much better than the code I had been using for a long time).
In column A I have created an identifier to provide an * if the data is not required and blank if it is. Then I run the code to find those rows and delete them. However, with almost 50000 rows of data, it is very time consuming. The end result is around 800 rows.
First, is there a better way to work with so much data without deleting portions of the whole data?
Second, the code below works but takes a long amount of time. Is there a more efficient way?
Const xlUp As Long = -4162
Sub DeleteMarkedRows2016()
Dim lastrow
Dim Rng As Range
Dim ws As Worksheet
Set ws = ActiveSheet
Application.ScreenUpdating = False
'Determine last row of data in worksheet
With ws
If WorksheetFunction.CountA(.Cells) <> 0 Then
lastrow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastrow = 1
End If
Set Rng = ws.Range("A1:A" & lastrow)
Debug.Print Rng.Address
End With
Dim MySel As Range
'Create a collection of rows to be deleted and delete
For Each cell In Rng
If cell.Value = "*" Then
If MySel Is Nothing Then
Set MySel = Rows(cell.Row)
Else
Set MySel = Union(MySel, Rows(cell.Row))
End If
End If
Next cell
If Not MySel Is Nothing Then
With MySel
.Delete
End With
End If
Application.ScreenUpdating = True
End Sub
Bookmarks