Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Poblem with a macro

This macro sends rows from Sheet1 to Sheet2, when it finds an "A" in
the firt cell of the row in Sheet1, sends it to Sheet2. But when there
is no more "A" in the other rows it sends the rows even they dont have
an "A" in their first cell. When it ends all the rows with data and the
Sheet is empty, an error window appears to debug the macro. I do not
know what to do. The macro must take only the rows with "A" in the firs
cell from the left side and move them to Sheet2. If there are not rows
that have "A", then it has to stop moving rows to the other Sheet.

Thanks for your help.

Sub Traspasa_datos()
Application.ScreenUpdating = False
With Worksheets("Sheet1")
If .AutoFilterMode Then .Cells.AutoFilter
.[a1].AutoFilter Field:=1, Criteria1:="A"
With .AutoFilter.Range
With .Offset(1).Resize(.Rows.Count - 1)
.Copy Worksheets("Sheet2").[a65536].End(xlUp).Offset(1)
.EntireRow.Delete
End With
End With
.[a1].AutoFilter
.UsedRange
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Poblem with a macro

This line works with the data in the autofilter range:

With .Offset(1).Resize(.Rows.Count - 1)

First, it copies it. Then it deletes it.

I bet you want just the visible rows:

With .Offset(1).Resize(.Rows.Count - 1).cells.specialcells(xlcelltypevisible)

======
You may want to check if there's always a visible row.

if .autofilter.range.columns(1).cells.specialcells(xl celltypevisible).count _
= 1 then
'only the header row--no details
else
'do all that copy|delete
end if

Untested, uncompiled. Watch out for typos.


Maxwell wrote:

This macro sends rows from Sheet1 to Sheet2, when it finds an "A" in
the firt cell of the row in Sheet1, sends it to Sheet2. But when there
is no more "A" in the other rows it sends the rows even they dont have
an "A" in their first cell. When it ends all the rows with data and the
Sheet is empty, an error window appears to debug the macro. I do not
know what to do. The macro must take only the rows with "A" in the firs
cell from the left side and move them to Sheet2. If there are not rows
that have "A", then it has to stop moving rows to the other Sheet.

Thanks for your help.

Sub Traspasa_datos()
Application.ScreenUpdating = False
With Worksheets("Sheet1")
If .AutoFilterMode Then .Cells.AutoFilter
.[a1].AutoFilter Field:=1, Criteria1:="A"
With .AutoFilter.Range
With .Offset(1).Resize(.Rows.Count - 1)
.Copy Worksheets("Sheet2").[a65536].End(xlUp).Offset(1)
.EntireRow.Delete
End With
End With
.[a1].AutoFilter
.UsedRange
End With
End Sub


--

Dave Peterson
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Need syntax for RUNning a Word macro with an argument, called from an Excel macro Steve[_84_] Excel Programming 3 July 6th 06 07:42 PM
DIAS.LAB function poblem Gerardo Excel Worksheet Functions 1 October 31st 05 06:22 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 05:07 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"