PC Review


Reply
Thread Tools Rate Thread

Copying parts of a sheet with macro

 
 
Roger Dodger
Guest
Posts: n/a
 
      30th Sep 2010
Hi All,

recently I have learned how to record and use macros (with a fair bit of
help from this group) and I have got them working well, except for one.

At present I click on the macro and it goes to sheet 2 and selects and
copies A2 down to end of data, then pastes it in sheet 1 from A6 down.
Next it goes back to Sheet 2 and selects C2 accross to end of data and then
down to end of data and copies it and pastes it into sheet 1 from C6 down to
bottom.
There are about 1800 rows and it takes a while to do. I must be impatient.
On Sheet 1 column B is vlookup for other relevant data. I am not sure that
this makes a difference.

This macro works however is there a better way to do this easier or maybe
faster?

Thanks
Kevin


 
Reply With Quote
 
 
 
 
Pete_UK
Guest
Posts: n/a
 
      1st Oct 2010
Post the code that you are using. If this has been produced by
recording keystrokes, then there are probably many selections made,
and these can often be improved on.

Pete

On Sep 30, 11:22*pm, "Roger Dodger" <gtsmonaro...@bigpond.com> wrote:
> Hi All,
>
> recently I have learned how to record and use *macros (with a fair bit of
> help from this group) and I have got them working well, except for one.
>
> At present I click on the macro and it goes to sheet 2 and selects and
> copies A2 down to end of data, then pastes it in sheet 1 from A6 down.
> Next it goes back to Sheet 2 and selects *C2 accross to end of data andthen
> down to end of data and copies it and pastes it into sheet 1 from C6 downto
> bottom.
> There are about 1800 rows and it takes a while to do. I must be impatient..
> On Sheet 1 column B is vlookup for other relevant data. I am not sure that
> this makes a difference.
>
> This macro works however is there a better way to do this easier or maybe
> faster?
>
> Thanks
> Kevin


 
Reply With Quote
 
Roger Dodger
Guest
Posts: n/a
 
      1st Oct 2010
Here it is Pete


Sheets("Raw data").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Sheet1").Select
Range("A6").Select
ActiveSheet.Paste
Sheets("Raw data").Select
Range("C2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("A2").Select
Sheets("Sheet1").Select
Range("C6").Select
ActiveSheet.Paste
Range("A6").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Range("B8").Select
Range("A5:N1799").Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=
_
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010", Operator:=xlAnd
End Sub


"Pete_UK" <(E-Mail Removed)> wrote in message
news:b9c53923-1125-456a-8b2f-(E-Mail Removed)...
Post the code that you are using. If this has been produced by
recording keystrokes, then there are probably many selections made,
and these can often be improved on.

Pete

On Sep 30, 11:22 pm, "Roger Dodger" <gtsmonaro...@bigpond.com> wrote:
> Hi All,
>
> recently I have learned how to record and use macros (with a fair bit of
> help from this group) and I have got them working well, except for one.
>
> At present I click on the macro and it goes to sheet 2 and selects and
> copies A2 down to end of data, then pastes it in sheet 1 from A6 down.
> Next it goes back to Sheet 2 and selects C2 accross to end of data and
> then
> down to end of data and copies it and pastes it into sheet 1 from C6 down
> to
> bottom.
> There are about 1800 rows and it takes a while to do. I must be impatient.
> On Sheet 1 column B is vlookup for other relevant data. I am not sure that
> this makes a difference.
>
> This macro works however is there a better way to do this easier or maybe
> faster?
>
> Thanks
> Kevin



 
Reply With Quote
 
Don Guillett Excel MVP
Guest
Posts: n/a
 
      1st Oct 2010
On Oct 1, 4:48*am, "Roger Dodger" <gtsmonaro...@bigpond.com> wrote:
> Here it is Pete
>
> * * Sheets("Raw data").Select
> * * Range("A2").Select
> * * Range(Selection, Selection.End(xlDown)).Select
> * * Selection.Copy
> * * Sheets("Sheet1").Select
> * * Range("A6").Select
> * * ActiveSheet.Paste
> * * Sheets("Raw data").Select
> * * Range("C2").Select
> * * Range(Selection, Selection.End(xlToRight)).Select
> * * Range(Selection, Selection.End(xlDown)).Select
> * * Application.CutCopyMode = False
> * * Selection.Copy
> * * ActiveWindow.ScrollColumn = 2
> * * ActiveWindow.ScrollColumn = 1
> * * Range("A2").Select
> * * Sheets("Sheet1").Select
> * * Range("C6").Select
> * * ActiveSheet.Paste
> * * Range("A6").Select
> * * Range(Selection, Selection.End(xlToRight)).Select
> * * Range(Selection, Selection.End(xlDown)).Select
> * * Application.CutCopyMode = False
> * * Selection.Borders(xlDiagonalDown).LineStyle = xlNone
> * * Selection.Borders(xlDiagonalUp).LineStyle = xlNone
> * * With Selection.Borders(xlEdgeLeft)
> * * * * .LineStyle = xlContinuous
> * * * * .Weight = xlThin
> * * * * .ColorIndex = xlAutomatic
> * * End With
> * * With Selection.Borders(xlEdgeTop)
> * * * * .LineStyle = xlContinuous
> * * * * .Weight = xlThin
> * * * * .ColorIndex = xlAutomatic
> * * End With
> * * With Selection.Borders(xlEdgeBottom)
> * * * * .LineStyle = xlContinuous
> * * * * .Weight = xlThin
> * * * * .ColorIndex = xlAutomatic
> * * End With
> * * With Selection.Borders(xlEdgeRight)
> * * * * .LineStyle = xlContinuous
> * * * * .Weight = xlThin
> * * * * .ColorIndex = xlAutomatic
> * * End With
> * * With Selection.Borders(xlInsideVertical)
> * * * * .LineStyle = xlContinuous
> * * * * .Weight = xlThin
> * * * * .ColorIndex = xlAutomatic
> * * End With
> * * With Selection.Borders(xlInsideHorizontal)
> * * * * .LineStyle = xlContinuous
> * * * * .Weight = xlThin
> * * * * .ColorIndex = xlAutomatic
> * * End With
> * * Range("B8").Select
> * * Range("A5:N1799").Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=
> _
> * * * * xlGuess, OrderCustom:=1, MatchCase:=False,
> Orientation:=xlTopToBottom, _
> * * * * DataOption1:=xlSortNormal
> * * Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010", Operator:=xlAnd
> End Sub
>
> "Pete_UK" <pashu...@auditel.net> wrote in message
>
> news:b9c53923-1125-456a-8b2f-(E-Mail Removed)...
> Post the code that you are using. If this has been produced by
> recording keystrokes, then there are probably many selections made,
> and these can often be improved on.
>
> Pete
>
> On Sep 30, 11:22 pm, "Roger Dodger" <gtsmonaro...@bigpond.com> wrote:
>
>
>
> > Hi All,

>
> > recently I have learned how to record and use macros (with a fair bit of
> > help from this group) and I have got them working well, except for one.

>
> > At present I click on the macro and it goes to sheet 2 and selects and
> > copies A2 down to end of data, then pastes it in sheet 1 from A6 down.
> > Next it goes back to Sheet 2 and selects C2 accross to end of data and
> > then
> > down to end of data and copies it and pastes it into sheet 1 from C6 down
> > to
> > bottom.
> > There are about 1800 rows and it takes a while to do. I must be impatient.
> > On Sheet 1 column B is vlookup for other relevant data. I am not sure that
> > this makes a difference.

>
> > This macro works however is there a better way to do this easier or maybe
> > faster?

>
> > Thanks
> > Kevin- Hide quoted text -

>
> - Show quoted text -


try this
with Sheets("Raw data")
.Range("a2", Range("a2").End(xlDown)).copy
Sheets("Sheet1").Range("A6")
.Range("c2", Range("a2").End(xlDown).End(xlToRight)).copy
Sheets("Sheet1").Range("C6")
.Range("a6",
Range("a6").End(xlDown).End(xlToRight)).borders.linestyle=xlContinuous
.Range("A5:N1799").Sort Key1:=Range("B5"), Order1:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010",
Operator:=xlAnd
end with
End Sub

 
Reply With Quote
 
Don Guillett Excel MVP
Guest
Posts: n/a
 
      1st Oct 2010
On Oct 1, 8:04*am, Don Guillett Excel MVP <dguille...@austin.rr.com>
wrote:
> On Oct 1, 4:48*am, "Roger Dodger" <gtsmonaro...@bigpond.com> wrote:
>
>
>
>
>
> > Here it is Pete

>
> > * * Sheets("Raw data").Select
> > * * Range("A2").Select
> > * * Range(Selection, Selection.End(xlDown)).Select
> > * * Selection.Copy
> > * * Sheets("Sheet1").Select
> > * * Range("A6").Select
> > * * ActiveSheet.Paste
> > * * Sheets("Raw data").Select
> > * * Range("C2").Select
> > * * Range(Selection, Selection.End(xlToRight)).Select
> > * * Range(Selection, Selection.End(xlDown)).Select
> > * * Application.CutCopyMode = False
> > * * Selection.Copy
> > * * ActiveWindow.ScrollColumn = 2
> > * * ActiveWindow.ScrollColumn = 1
> > * * Range("A2").Select
> > * * Sheets("Sheet1").Select
> > * * Range("C6").Select
> > * * ActiveSheet.Paste
> > * * Range("A6").Select
> > * * Range(Selection, Selection.End(xlToRight)).Select
> > * * Range(Selection, Selection.End(xlDown)).Select
> > * * Application.CutCopyMode = False
> > * * Selection.Borders(xlDiagonalDown).LineStyle = xlNone
> > * * Selection.Borders(xlDiagonalUp).LineStyle = xlNone
> > * * With Selection.Borders(xlEdgeLeft)
> > * * * * .LineStyle = xlContinuous
> > * * * * .Weight = xlThin
> > * * * * .ColorIndex = xlAutomatic
> > * * End With
> > * * With Selection.Borders(xlEdgeTop)
> > * * * * .LineStyle = xlContinuous
> > * * * * .Weight = xlThin
> > * * * * .ColorIndex = xlAutomatic
> > * * End With
> > * * With Selection.Borders(xlEdgeBottom)
> > * * * * .LineStyle = xlContinuous
> > * * * * .Weight = xlThin
> > * * * * .ColorIndex = xlAutomatic
> > * * End With
> > * * With Selection.Borders(xlEdgeRight)
> > * * * * .LineStyle = xlContinuous
> > * * * * .Weight = xlThin
> > * * * * .ColorIndex = xlAutomatic
> > * * End With
> > * * With Selection.Borders(xlInsideVertical)
> > * * * * .LineStyle = xlContinuous
> > * * * * .Weight = xlThin
> > * * * * .ColorIndex = xlAutomatic
> > * * End With
> > * * With Selection.Borders(xlInsideHorizontal)
> > * * * * .LineStyle = xlContinuous
> > * * * * .Weight = xlThin
> > * * * * .ColorIndex = xlAutomatic
> > * * End With
> > * * Range("B8").Select
> > * * Range("A5:N1799").Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=
> > _
> > * * * * xlGuess, OrderCustom:=1, MatchCase:=False,
> > Orientation:=xlTopToBottom, _
> > * * * * DataOption1:=xlSortNormal
> > * * Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010", Operator:=xlAnd
> > End Sub

>
> > "Pete_UK" <pashu...@auditel.net> wrote in message

>
> >news:b9c53923-1125-456a-8b2f-(E-Mail Removed)....
> > Post the code that you are using. If this has been produced by
> > recording keystrokes, then there are probably many selections made,
> > and these can often be improved on.

>
> > Pete

>
> > On Sep 30, 11:22 pm, "Roger Dodger" <gtsmonaro...@bigpond.com> wrote:

>
> > > Hi All,

>
> > > recently I have learned how to record and use macros (with a fair bitof
> > > help from this group) and I have got them working well, except for one.

>
> > > At present I click on the macro and it goes to sheet 2 and selects and
> > > copies A2 down to end of data, then pastes it in sheet 1 from A6 down..
> > > Next it goes back to Sheet 2 and selects C2 accross to end of data and
> > > then
> > > down to end of data and copies it and pastes it into sheet 1 from C6 down
> > > to
> > > bottom.
> > > There are about 1800 rows and it takes a while to do. I must be impatient.
> > > On Sheet 1 column B is vlookup for other relevant data. I am not surethat
> > > this makes a difference.

>
> > > This macro works however is there a better way to do this easier or maybe
> > > faster?

>
> > > Thanks
> > > Kevin- Hide quoted text -

>
> > - Show quoted text -

>
> try this
> with Sheets("Raw data")
> * *.Range("a2", Range("a2").End(xlDown)).copy
> Sheets("Sheet1").Range("A6")
> * *.Range("c2", Range("a2").End(xlDown).End(xlToRight)).copy
> Sheets("Sheet1").Range("C6")
> * *.Range("a6",
> Range("a6").End(xlDown).End(xlToRight)).borders.linestyle=xlContinuous
> * *.Range("A5:N1799").Sort Key1:=Range("B5"), Order1:=xlAscending,
> Header:= *_
> * * * xlGuess, OrderCustom:=1, MatchCase:=False,
> Orientation:=xlTopToBottom, _
> * * Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010",
> Operator:=xlAnd
> end with
> End Sub- Hide quoted text -
>
> - Show quoted text -


Be sure to correct for word wrap
 
Reply With Quote
 
Roger Dodger
Guest
Posts: n/a
 
      2nd Oct 2010


> with Sheets("Raw data")
> .Range("a2", Range("a2").End(xlDown)).copy
> Sheets("Sheet1").Range("A6")
> .Range("c2", Range("a2").End(xlDown).End(xlToRight)).copy
> Sheets("Sheet1").Range("C6")
> .Range("a6",


I get a compile error Here

> Range("a6").End(xlDown).End(xlToRight)).borders.linestyle=xlContinuous
> .Range("A5:N1799").Sort Key1:=Range("B5"), Order1:=xlAscending,
> Header:= _
> xlGuess, OrderCustom:=1, MatchCase:=False,
> Orientation:=xlTopToBottom, _
> Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010",
> Operator:=xlAnd
> end with
> End Sub- Hide quoted text -
>
> - Show quoted text -




 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Oct 2010
There are some Range objects that need a leading dot:

with Sheets("Raw data")
.Range("a2", .Range("a2").End(xlDown)).copy
Sheets("Sheet1").Range("A6")

.Range("c2", .Range("a2").End(xlDown).End(xlToRight)).copy
Sheets("Sheet1").Range("C6")

.Range("a6", _
.Range("a6").End(xlDown).End(xlToRight)).borders.linestyle=xlContinuous

.Range("A5:N1799").Sort Key1:=.Range("B5"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _

'This is working on the selection -- which may not be what you
'want!
Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010",

end with
End Sub


On 10/02/2010 17:10, Roger Dodger wrote:
>> with Sheets("Raw data")
>> .Range("a2", Range("a2").End(xlDown)).copy
>> Sheets("Sheet1").Range("A6")
>> .Range("c2", Range("a2").End(xlDown).End(xlToRight)).copy
>> Sheets("Sheet1").Range("C6")
>> .Range("a6",

>
> I get a compile error Here
>
>> Range("a6").End(xlDown).End(xlToRight)).borders.linestyle=xlContinuous
>> .Range("A5:N1799").Sort Key1:=Range("B5"), Order1:=xlAscending,
>> Header:= _
>> xlGuess, OrderCustom:=1, MatchCase:=False,
>> Orientation:=xlTopToBottom, _
>> Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010",
>> Operator:=xlAnd
>> end with
>> End Sub- Hide quoted text -
>>
>> - Show quoted text -

>
>
>


--
Dave Peterson
 
Reply With Quote
 
Don Guillett Excel MVP
Guest
Posts: n/a
 
      6th Oct 2010
On Oct 2, 9:40*pm, Dave Peterson <peter...@XSPAMverizon.net> wrote:
> There are some Range objects that need a leading dot:
>
> with Sheets("Raw data")
> * * .Range("a2", .Range("a2").End(xlDown)).copy
> * * * * Sheets("Sheet1").Range("A6")
>
> * * .Range("c2", .Range("a2").End(xlDown).End(xlToRight)).copy
> * * * * Sheets("Sheet1").Range("C6")
>
> * * .Range("a6", _
> * * * *.Range("a6").End(xlDown).End(xlToRight)).borders.linestyle=xlContinuous
>
> * * .Range("A5:N1799").Sort Key1:=.Range("B5"), Order1:=xlAscending, _
> * * * *Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
> * * * *Orientation:=xlTopToBottom, _
>
> * * *'This is working on the selection -- which may not be what you
> * * *'want!
> * * *Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010",
>
> end with
> End Sub
>
> On 10/02/2010 17:10, Roger Dodger wrote:
>
>
>
>
>
> >> with Sheets("Raw data")
> >> .Range("a2", Range("a2").End(xlDown)).copy
> >> Sheets("Sheet1").Range("A6")
> >> .Range("c2", Range("a2").End(xlDown).End(xlToRight)).copy
> >> Sheets("Sheet1").Range("C6")
> >> .Range("a6",

>
> > I get a compile error Here

>
> >> Range("a6").End(xlDown).End(xlToRight)).borders.linestyle=xlContinuous
> >> .Range("A5:N1799").Sort Key1:=Range("B5"), Order1:=xlAscending,
> >> Header:= _
> >> xlGuess, OrderCustom:=1, MatchCase:=False,
> >> Orientation:=xlTopToBottom, _
> >> Selection.AutoFilter Field:=3, Criteria1:=">4-Aug-2010",
> >> Operator:=xlAnd
> >> end with
> >> End Sub- Hide quoted text -

>
> >> - Show quoted text -

>
> --
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


Also missing line continuation. Surely your vba editor is showing in
red...
If you still have problems send me your file to (E-Mail Removed)
and this msg.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 questions, copying data from sheet to sheet and assigning macro =?Utf-8?B?Qm9yaXM=?= Microsoft Excel Worksheet Functions 0 16th Dec 2004 06:11 PM
MACRO for copying active sheet without using a certain name Tami Microsoft Excel Programming 3 27th Jul 2004 04:47 AM
copying data to another sheet using a macro claire Microsoft Excel Worksheet Functions 0 9th Jan 2004 04:52 PM
copying sheet with macro mcrmike Microsoft Excel Programming 2 7th Jan 2004 08:22 PM
Copying active sheet in a macro David P. Microsoft Excel Worksheet Functions 2 19th Dec 2003 08:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:27 AM.