View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Deleting blank rows with formulas in them

oops,,
There's a bug in that, try this instead

Sub marine()
Dim ws As Worksheet
Dim MyRange As Range
Dim CopyRange As Range
S = "Sheet1,Sheet2,Sheet9" 'Change to suit
V = Split(S, ",")
For Each ws In ThisWorkbook.Worksheets
If Not IsError(Application.Match(ws.Name, V, 0)) Then
Set MyRange = ws.Range("A8:A800" & lastrow)
For Each c In MyRange
If WorksheetFunction.Count(ws.Range("A" & c.Row & ":" & "P" & c.Row)) =
0 Then
If CopyRange Is Nothing Then
Set CopyRange = c.EntireRow
Else
Set CopyRange = Union(CopyRange, c.EntireRow)
End If
End If
Next
End If
If Not CopyRange Is Nothing Then
CopyRange.Delete
Set CopyRange = Nothing
End If
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

Try this,

Change the list of sheet names to the ones you want to work on

Sub marine()
Dim ws As Worksheet
Dim MyRange As Range
Dim CopyRange As Range
S = "Sheet1,Sheet2,Sheet9" 'Change to suit
V = Split(S, ",")
For Each ws In ThisWorkbook.Worksheets
If Not IsError(Application.Match(ws.Name, V, 0)) Then
Set MyRange = ws.Range("A8:A800")
For Each c In MyRange
If WorksheetFunction.Count(Range("A" & c.Row & ":" & "P" & c.Row)) = 0
Then
If CopyRange Is Nothing Then
Set CopyRange = c.EntireRow
Else
Set CopyRange = Union(CopyRange, c.EntireRow)
End If
End If
Next
End If
If Not CopyRange Is Nothing Then
CopyRange.Delete
Set CopyRange = Nothing
End If
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Kennedy" wrote:

Mike,
All Columns. In this case, I have formulas in rows 8-300, columns A-P. So if
the formulas returns data back in rows 8-100, columns A-P, keep that, but
delete all formulas from 101-300, columns A-P.
The one thing consistent in all worksheets is that the data starts on row 8,
and use columns A-P

"Mike H" wrote:

Hi,

Which columns are we looking at in these rows, all of them?
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Kennedy" wrote:

I have a spreadsheet that takes data from one worksheet and moves it to
several worksheets, depending on a certain value. There are several
worksheets where the data has been moved, based on a macro and formula I
wrote.
There are several rows that will always be blank, however a formula appears
in those rows. Is there a way to create a macro that will look at all the
"named" sheets individually and find any rows from 8-300 that have a formula
in them, but do not contain actual data.
For instance, worksheet NEO has formulas that feed off another sheet from
row 8-300. However, only data appears in rows 8-125. Rows 126-300 are blank
but contain a formula. How can that e deleted.
Same thing with worksheet OEN, except data is present in rows 8-100, with
101-300 being blank but containint formulas.
Same with other worksheets.