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

Hi,

I have a code but cant figure out how to change it so its just copies
everything rather than filter and then copy, the reason it filters is because
i copied this code from a filer code (but did think i removed all the filter
code bit.. obviously not!)

I think it might be this bit that is causing the problem: lastrow =
Cells(Cells.Rows.Count, "F").End(xlUp).Row
Set myrange = Range("F1:F" & lastrow)


All the code:

Sub CTS()
Sheets("A").Select
Dim myrange, copyrange As Range
Set copyrange = Rows(1).EntireRow
lastrow = Cells(Cells.Rows.Count, "F").End(xlUp).Row
Set myrange = Range("F1:F" & lastrow)
For Each c In myrange


Set copyrange = Union(copyrange, c.EntireRow)

Next
copyrange.Copy
Worksheets.Add(After:=Worksheets(Worksheets.Count) ).Name = "B"
ActiveSheet.Paste
With ActiveSheet
.Range("D:D,H:I,K:L,N:U,W:AD,AF:AT,AV:IV").Delete

End With

Worksheets("B").Activate
Cells.Select
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub


thanks alot.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Simple macro

hi
your code is coping all date from the last row in column F that has data up
or meaning all rows have should have data. you would get into problems if
there was data below the last cell in F .
copy all?
Replace all code from Sheets("A").Select to ActiveSheet.Paste with this....
Sheets("A").Activate
Cells.Copy
Worksheets.Add(After:=Worksheets(Worksheets.Count) ).Name = "B"
ActiveSheet.Paste

regards
FSt1

"Gemz" wrote:

Hi,

I have a code but cant figure out how to change it so its just copies
everything rather than filter and then copy, the reason it filters is because
i copied this code from a filer code (but did think i removed all the filter
code bit.. obviously not!)

I think it might be this bit that is causing the problem: lastrow =
Cells(Cells.Rows.Count, "F").End(xlUp).Row
Set myrange = Range("F1:F" & lastrow)


All the code:

Sub CTS()
Sheets("A").Select
Dim myrange, copyrange As Range
Set copyrange = Rows(1).EntireRow
lastrow = Cells(Cells.Rows.Count, "F").End(xlUp).Row
Set myrange = Range("F1:F" & lastrow)
For Each c In myrange


Set copyrange = Union(copyrange, c.EntireRow)

Next
copyrange.Copy
Worksheets.Add(After:=Worksheets(Worksheets.Count) ).Name = "B"
ActiveSheet.Paste
With ActiveSheet
.Range("D:D,H:I,K:L,N:U,W:AD,AF:AT,AV:IV").Delete

End With

Worksheets("B").Activate
Cells.Select
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub


thanks alot.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Simple macro

Hi
Made a few changes. Comments are next to changed lines. Nothing in
your code filters anything, so a filter must be applied elsewhere.

Sub CTS()
Sheets("A").Select
Dim myrange as Range 'myrange not declared properly, copyrange not
needed
lastrow = Cells(Rows.Count, "F").End(xlUp).Row 'extra cells not
needed
Set myrange = Range("F1:F" & lastrow) .EntireRow 'includes Row 1 i.e.
copyrange
myrange.Copy
Worksheets.Add(After:=Worksheets(Worksheets.Count) ).Name = "B"
ActiveSheet.Paste
With ActiveSheet
.Range("D:D,H:I,K:L,N:U,W:AD,AF:AT,AV:IV").Delete
End With
Worksheets("B").Activate
Cells.Select
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
'sub doesn't set Displayalerts etc to false, so no need to make them
true
End Sub

regards
Paul


On Feb 22, 11:44*am, Gemz wrote:
Hi,

I have a code but cant figure out how to change it so its just copies
everything rather than filter and then copy, the reason it filters is because
i copied this code from a filer code (but did think i removed all the filter
code bit.. obviously not!)

I think it might be this bit that is causing the problem: lastrow =
Cells(Cells.Rows.Count, "F").End(xlUp).Row
Set myrange = Range("F1:F" & lastrow)

All the code:

Sub CTS()
Sheets("A").Select
Dim myrange, copyrange As Range
Set copyrange = Rows(1).EntireRow
lastrow = Cells(Cells.Rows.Count, "F").End(xlUp).Row
Set myrange = Range("F1:F" & lastrow)
For Each c In myrange

* * * * * * * * Set copyrange = Union(copyrange, c.EntireRow)

Next
copyrange.Copy
Worksheets.Add(After:=Worksheets(Worksheets.Count) ).Name = "B"
ActiveSheet.Paste
With ActiveSheet
* * * * .Range("D:D,H:I,K:L,N:U,W:AD,AF:AT,AV:IV").Delete

End With

* * Worksheets("B").Activate
* * * * Cells.Select
* * Cells.EntireColumn.AutoFit
* * Cells.EntireRow.AutoFit
With Application
* * .DisplayAlerts = True
* * .EnableEvents = True
* * .ScreenUpdating = True
End With
End Sub

thanks alot.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Simple macro

Hi Gemz

Thought i would join in here... It would seem that you want to copy
all the data in a worksheet then create a new worksheet and paste this
data into it? Would it not be easier to copy the and paste the
worksheet rather than what it holds??? Anywho the code below would do
just that.

Option Explicit
Dim i As Integer

Private Sub CommandButton1_Click()

i = Worksheets.Count

Sheets("Sheet3").Copy After:=Sheets(i)


With Sheets(i + 1)

.Name = "B"

.Cells.EntireColumn.AutoFit

.Cells.EntireRow.AutoFit

End With

End Sub

Steve
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
Simple Macro? Felix Excel Programming 1 July 24th 07 04:52 PM
Simple Macro John Excel Worksheet Functions 1 November 17th 06 05:16 PM
Simple Macro OCONUS Excel Programming 1 October 31st 06 07:16 PM
a simple macro? asalerno Excel Discussion (Misc queries) 2 April 28th 06 12:45 AM
Simple help with macro please Brian Tozer Excel Programming 4 December 26th 03 06:45 PM


All times are GMT +1. The time now is 10:41 AM.

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"