shipleyscott
New Member
- Joined
- Aug 24, 2017
- Messages
- 7
I wrote a macro that I use to analyze the outputs of a 2-d hydraulic flow model. It gets rid of the junk data and moves the data I want to analyze near the "origin" of the webpage. It worked on a pretty large data set when we had a 3' sized grid, but the excel crashes when I run it on the output of a 1' sized matrix. It is about 4500 x 4500 cells in size before I run the macro. The macro looks like:
Sub removeinplace()
‘This sub replaces all of the junk data (-9999) with blank cells but does not affect cells that do not have (-‘9999) in them.
‘This sub calls DeleteBlankColumns and DeleteBlankRows to move the cluster (it is a contiguous
‘cluster) ‘of data closer to the origin where I can work with it.
' define Myrange
Set MyRange = ActiveSheet.UsedRange
With ActiveSheet.UsedRange
.Replace -9999, "", xlWhole, SearchFormat:=False, ReplaceFormat:=False
End With
Call DeleteBlankColumns
Call DeleteBlankRows
End Sub
Sub DeleteBlankColumns()
‘This sub deletes blank columns
'Step1: Declare your variables.
Dim iCounter As Long
Dim MaxColumns As Long
'Step 2: Define the target Range.
With ActiveSheet
MaxColumns = ActiveSheet.Range("B1").Value
'Step 3: Start reverse looping through the range.
For iCounter = MaxColumns To 1 Step -1
'Step 4: If entire column is empty then delete it.
If Application.CountA(Columns(iCounter).EntireColumn) = 0 Then
Columns(iCounter).Delete
End If
'Step 5: Increment the counter down
Next iCounter
End With
End Sub
------------------------------------------------------------------------------------------------------------------------------------------
Sub DeleteBlankRows()
‘This sub deletes blank rows.
'Step1: Declare your variables.
Dim iCounter As Long
Dim MaxRows As Long
'Step 2: Define the target Range.
With ActiveSheet
MaxRows = ActiveSheet.Range("B2").Value
'Step 3: Start reverse looping through the range.
For iCounter = MaxRows To 1 Step -1
'Step 4: If entire row is empty then delete it.
If Application.CountA(Rows(iCounter).EntireRow) = 0 Then
Rows(iCounter).Delete
End If
'Step 5: Increment the counter down
Next iCounter
End With
End Sub
What am I doing wrong?
(I wasn't able to load sample data because it was too large of a file).
Sub removeinplace()
‘This sub replaces all of the junk data (-9999) with blank cells but does not affect cells that do not have (-‘9999) in them.
‘This sub calls DeleteBlankColumns and DeleteBlankRows to move the cluster (it is a contiguous
‘cluster) ‘of data closer to the origin where I can work with it.
' define Myrange
Set MyRange = ActiveSheet.UsedRange
With ActiveSheet.UsedRange
.Replace -9999, "", xlWhole, SearchFormat:=False, ReplaceFormat:=False
End With
Call DeleteBlankColumns
Call DeleteBlankRows
End Sub
Sub DeleteBlankColumns()
‘This sub deletes blank columns
'Step1: Declare your variables.
Dim iCounter As Long
Dim MaxColumns As Long
'Step 2: Define the target Range.
With ActiveSheet
MaxColumns = ActiveSheet.Range("B1").Value
'Step 3: Start reverse looping through the range.
For iCounter = MaxColumns To 1 Step -1
'Step 4: If entire column is empty then delete it.
If Application.CountA(Columns(iCounter).EntireColumn) = 0 Then
Columns(iCounter).Delete
End If
'Step 5: Increment the counter down
Next iCounter
End With
End Sub
------------------------------------------------------------------------------------------------------------------------------------------
Sub DeleteBlankRows()
‘This sub deletes blank rows.
'Step1: Declare your variables.
Dim iCounter As Long
Dim MaxRows As Long
'Step 2: Define the target Range.
With ActiveSheet
MaxRows = ActiveSheet.Range("B2").Value
'Step 3: Start reverse looping through the range.
For iCounter = MaxRows To 1 Step -1
'Step 4: If entire row is empty then delete it.
If Application.CountA(Rows(iCounter).EntireRow) = 0 Then
Rows(iCounter).Delete
End If
'Step 5: Increment the counter down
Next iCounter
End With
End Sub
What am I doing wrong?
(I wasn't able to load sample data because it was too large of a file).