#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 55
Default #REF! help please

Hi Folks,

Using this code, I'm copying a range of cells from one sheet to
another (Thanks to Simon for the code)
~~~~~~~~~~~
Public Sw As Long
Sub HideRows()
Dim Rng As Range, MyCell As Range
Set Rng = Sheets("Sheet1").Range("B29:B" & Range("B" &
Rows.Count).End(xlUp).Row)
If Sw = 1 Then
Rng.Rows.Hidden = False
Sw = 0
Exit Sub
End If
For Each MyCell In Rng
If MyCell.Value = 0 Then
MyCell.Rows.Hidden = True
Sw = 1
End If
Next MyCell
Rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy
Destination:=Sheets("Sheet2").Range("A3")
End Sub
~~~~~~~~~~~~~

The problem is that the new sheet contains mostly #REF! errors. I
have tried xlCellTypeAllFormatConditions instead but I get a VB error
that says "Run-time error '1004': Application-defined or object-
defined error"

Any suggestions? If you cannot tell, I am a VBA dolt. :)

Many thanks!
Craig
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default #REF! help please

It looks like you have formulas that need to be change to values. I made a
few simply changes to use PasteSpecial

Public Sw As Long
Sub HideRows()
Dim Rng As Range, MyCell As Range
Set Rng = Sheets("Sheet1").Range("B29:B" & Range("B" & _
Rows.Count).End(xlUp).Row)
If Sw = 1 Then
Rng.Rows.Hidden = False
Sw = 0
Exit Sub
End If
For Each MyCell In Rng
If MyCell.Value = 0 Then
MyCell.Rows.Hidden = True
Sw = 1
End If
Next MyCell
Set MyRange = Rng.SpecialCells(xlCellTypeVisible)
MyRange.Copy
Sheets("Sheet2").Range("A3").PasteSpecial _
Paste:=xlPasteValues
End Sub


"TheMilkGuy" wrote:

Hi Folks,

Using this code, I'm copying a range of cells from one sheet to
another (Thanks to Simon for the code)
~~~~~~~~~~~
Public Sw As Long
Sub HideRows()
Dim Rng As Range, MyCell As Range
Set Rng = Sheets("Sheet1").Range("B29:B" & Range("B" &
Rows.Count).End(xlUp).Row)
If Sw = 1 Then
Rng.Rows.Hidden = False
Sw = 0
Exit Sub
End If
For Each MyCell In Rng
If MyCell.Value = 0 Then
MyCell.Rows.Hidden = True
Sw = 1
End If
Next MyCell
Rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy
Destination:=Sheets("Sheet2").Range("A3")
End Sub
~~~~~~~~~~~~~

The problem is that the new sheet contains mostly #REF! errors. I
have tried xlCellTypeAllFormatConditions instead but I get a VB error
that says "Run-time error '1004': Application-defined or object-
defined error"

Any suggestions? If you cannot tell, I am a VBA dolt. :)

Many thanks!
Craig

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 55
Default #REF! help please

Just about perfect Joel!

How could I modify this code to copy columns A through T to Sheet2
instead of just column B?

Thanks!
Craig

On Aug 13, 4:42*am, Joel wrote:
It looks like you have formulas that need to be change to values. *I made a
few simply changes to use PasteSpecial

Public Sw As Long
* Sub HideRows()
* Dim Rng As Range, MyCell As Range
* Set Rng = Sheets("Sheet1").Range("B29:B" & Range("B" & _
* * *Rows.Count).End(xlUp).Row)
* If Sw = 1 Then
* Rng.Rows.Hidden = False
* Sw = 0
* Exit Sub
* End If
* For Each MyCell In Rng
* If MyCell.Value = 0 Then
* MyCell.Rows.Hidden = True
* Sw = 1
* End If
* Next MyCell
* Set MyRange = Rng.SpecialCells(xlCellTypeVisible)
* MyRange.Copy
* Sheets("Sheet2").Range("A3").PasteSpecial _
* * *Paste:=xlPasteValues
* End Sub

"TheMilkGuy" wrote:
Hi Folks,


Using this code, I'm copying a range of cells from one sheet to
another (Thanks to Simon for the code)
~~~~~~~~~~~
* Public Sw As Long
* Sub HideRows()
* Dim Rng As Range, MyCell As Range
* Set Rng = Sheets("Sheet1").Range("B29:B" & Range("B" &
Rows.Count).End(xlUp).Row)
* If Sw = 1 Then
* Rng.Rows.Hidden = False
* Sw = 0
* Exit Sub
* End If
* For Each MyCell In Rng
* If MyCell.Value = 0 Then
* MyCell.Rows.Hidden = True
* Sw = 1
* End If
* Next MyCell
* Rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy
Destination:=Sheets("Sheet2").Range("A3")
* End Sub
~~~~~~~~~~~~~


The problem is that the new sheet contains mostly #REF! errors. *I
have tried xlCellTypeAllFormatConditions instead but I get a VB error
that says "Run-time error '1004': Application-defined or object-
defined error"


Any suggestions? *If you cannot tell, I am a VBA dolt. *:)


Many thanks!
Craig


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default #REF! help please

from
MyRange.Copy
to
MyRange.EntireRow.Copy


If it is copying to many columns then it is easy to delete the extra columns

Sheets("Sheet2").columns("U:IV").delete



"TheMilkGuy" wrote:

Just about perfect Joel!

How could I modify this code to copy columns A through T to Sheet2
instead of just column B?

Thanks!
Craig

On Aug 13, 4:42 am, Joel wrote:
It looks like you have formulas that need to be change to values. I made a
few simply changes to use PasteSpecial

Public Sw As Long
Sub HideRows()
Dim Rng As Range, MyCell As Range
Set Rng = Sheets("Sheet1").Range("B29:B" & Range("B" & _
Rows.Count).End(xlUp).Row)
If Sw = 1 Then
Rng.Rows.Hidden = False
Sw = 0
Exit Sub
End If
For Each MyCell In Rng
If MyCell.Value = 0 Then
MyCell.Rows.Hidden = True
Sw = 1
End If
Next MyCell
Set MyRange = Rng.SpecialCells(xlCellTypeVisible)
MyRange.Copy
Sheets("Sheet2").Range("A3").PasteSpecial _
Paste:=xlPasteValues
End Sub

"TheMilkGuy" wrote:
Hi Folks,


Using this code, I'm copying a range of cells from one sheet to
another (Thanks to Simon for the code)
~~~~~~~~~~~
Public Sw As Long
Sub HideRows()
Dim Rng As Range, MyCell As Range
Set Rng = Sheets("Sheet1").Range("B29:B" & Range("B" &
Rows.Count).End(xlUp).Row)
If Sw = 1 Then
Rng.Rows.Hidden = False
Sw = 0
Exit Sub
End If
For Each MyCell In Rng
If MyCell.Value = 0 Then
MyCell.Rows.Hidden = True
Sw = 1
End If
Next MyCell
Rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy
Destination:=Sheets("Sheet2").Range("A3")
End Sub
~~~~~~~~~~~~~


The problem is that the new sheet contains mostly #REF! errors. I
have tried xlCellTypeAllFormatConditions instead but I get a VB error
that says "Run-time error '1004': Application-defined or object-
defined error"


Any suggestions? If you cannot tell, I am a VBA dolt. :)


Many thanks!
Craig



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"