View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
davegb davegb is offline
external usenet poster
 
Posts: 573
Default Object required?


Dave Peterson wrote:
Your code worked fine for me after I declared all the variables.

Option Explicit
Sub testme02()
Dim RngCol As Range
Dim rCell As Range
Dim rngDel As Range
Dim lRow As Long

With ActiveSheet
lRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

Set RngCol = ActiveSheet.Range("A11:A" & lRow)
For Each rCell In RngCol.Cells
If rCell.value = "" Then
If rngDel Is Nothing Then
Set rngDel = rCell
Else
Set rngDel = Union(rCell, rngDel)
End If
End If
Next rCell

If rngDel Is Nothing Then
'do nothing
Else
rngDel.EntireRow.Delete
End If

End Sub

I don't see another reason why the union would be failing.

How did you declare your variables?

I copied the macro and the declarations into a separate module, then
ran it and it worked fine, just like yours did. So it must be something
about the first part of the macro. Here's the entire macro:

Dim Wksht As Worksheet
Dim lRow As Long
Dim rPay As Range
Dim rCell As Range
Dim rTtl As Range
Dim rRng As Range
Dim rngCol As Range
Dim rngDel As Range

Call Clean
lRow = 1000
Set Wksht = ActiveSheet
Wksht.Cells.RowHeight = 12.75

Wksht.Range("A8", "AE" & lRow).Select

Selection.UnMerge
Range("A10") = "Service County"

Range("B10") = "Service Provider Name"
Range("G10") = "Prov Id"
Range("H10") = "Lic Cert Type"
Range("I10") = "Effective Date"
Range("J10") = "Close Date"
Range("K10") = "Srvc Type"
Range("L10") = "Srvc Appr Status"
Range("O10") = "Gov Body Id"
Range("P10") = "Client Id"
Range("Q10") = "Client Last Name"
Range("R10") = "Client First Name"
Range("T10") = "Client State Id"
Range("U10") = "Client Srvc Begin Dt"
Range("V10") = "Client Srvd End Dt"
Range("W10") = "Pay Prvdr Y or N"
Range("Z10") = "IVE Entitlement Type"
Range("AC10") = "IVE Start Date"
Range("AE10") = "IVE End Date"

Range("W11").Activate


Set rPay = ActiveSheet.Range("W11", Cells(lRow, "W"))

For Each rCell In rPay
'rCell.Select

If rCell < "" Then
If rCell.Offset(0, -2) = "" Then

Range(rCell, rCell.Offset(0, 8)).Cut
Destination:=rCell.Offset(-1, 0)

End If
End If
Next

Range("F11:F" & lRow).Cut Destination:=Range("F11:F" & lRow).Offset(0,
1)
Range("AB11:AB" & lRow).Cut Destination:=Range("AB11:AB" &
lRow).Offset(0, 1)




Set rTtl = ActiveSheet.Range("a10:AE10")

For Each rCell In rTtl.Cells

If rCell.Value = "" Then
If rngDel Is Nothing Then

Set rngDel = rCell
Else
Set rngDel = Union(rCell, rngDel)

End If
Else
rCell.EntireColumn.AutoFit
End If
Next rCell

If rngDel Is Nothing Then
'nothing to delete
Else
rngDel.EntireColumn.Delete
End If

Set rngCol = ActiveSheet.Range("A11:A" & lRow)
For Each rCell In rngCol.Cells
If rCell = "" Then
If rngDel Is Nothing Then
Set rngDel = rCell
Else
Set rngDel = Union(rCell, rngDel)
End If
End If
Next rCell

If rngDel Is Nothing Then
'nothing to delete

Else
rngDel.EntireRow.Delete
End If

End Sub

Do you see what's causing the union to fail?