PC Review


Reply
Thread Tools Rate Thread

Condensing a macro

 
 
=?Utf-8?B?RXN0aGVySg==?=
Guest
Posts: n/a
 
      19th Apr 2006
The macro below copies some named ranges, pastes them into a new sheet and
then goes back copies 10 of the same ranges plus two new ones.This will have
to repeat its self 32 times to get the data the way I want it (make a
database from a table)! So if there is a way of condensing this macro or
make it more efficent I would be very grateful.

Thanks,

Esther


With
Worksheets("Master").Range("CUST,REG,RSM,MKTSEG,ATT,PLAT,CMACPN,CUSTPN,TECH,CUSTACC,MAY06OOH,MAY06PRICE").Copy
Sheets("New").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
'NEXT
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select

Worksheets("Master").Range("CUST,REG,RSM,MKTSEG,ATT,PLAT,CMACPN,CUSTPN,TECH,CUSTACC,MAY06FORC,MAY06PRICE").Copy
Sheets("New").Select
ActiveCell.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
'NEXT
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select

End With
End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?c2ViYXN0aWVubQ==?=
Guest
Posts: n/a
 
      19th Apr 2006
Hi
you could use a sub similar to:
'----------------------------------------------
'Copy origin range (RgO) and paste in last cell in
' destination (rgD) column
Sub AddDataToSheet(RgO As Range, RgD As Range)
Dim rg As Range
If RgO Is Nothing Or RgD Is Nothing Then Exit Sub

Set rg = RgD.EntireColumn
Set rg = rg.Cells(rg.Cells.Count).End(xlUp).Offset(1, 0)

RgO.Copy
RgD.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

End Sub
'---------------------------------------------------------

now call it using:
Sub test()
dim rg1 as range, rg2 as range

set
rg1=Worksheets("Master").Range("CUST,REG,RSM,MKTSEG,ATT,PLAT,CMACPN,CUSTPN,TECH,CUSTACC,MAY06OOH,MAY06PRICE")
set rg2=workSheets("New").range("A2")

'either call the sub each time or put in a loop.
AddDataToSheet rg1,rg2
AddDataToSheet rg1,rg2
AddDataToSheet rg1,rg2
end sub
--
Regards,
Sébastien
<http://www.ondemandanalysis.com>


"EstherJ" wrote:

> The macro below copies some named ranges, pastes them into a new sheet and
> then goes back copies 10 of the same ranges plus two new ones.This will have
> to repeat its self 32 times to get the data the way I want it (make a
> database from a table)! So if there is a way of condensing this macro or
> make it more efficent I would be very grateful.
>
> Thanks,
>
> Esther
>
>
> With
> Worksheets("Master").Range("CUST,REG,RSM,MKTSEG,ATT,PLAT,CMACPN,CUSTPN,TECH,CUSTACC,MAY06OOH,MAY06PRICE").Copy
> Sheets("New").Select
> Range("A2").Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> 'NEXT
> Range("A1").Select
> Selection.End(xlDown).Select
> ActiveCell.Offset(1, 0).Select
>
> Worksheets("Master").Range("CUST,REG,RSM,MKTSEG,ATT,PLAT,CMACPN,CUSTPN,TECH,CUSTACC,MAY06FORC,MAY06PRICE").Copy
> Sheets("New").Select
> ActiveCell.Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> 'NEXT
> Range("A1").Select
> Selection.End(xlDown).Select
> ActiveCell.Offset(1, 0).Select
>
> End With
> End Sub

 
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
Condensing a macro fgwiii Microsoft Excel Discussion 2 28th Jul 2009 02:26 PM
Condensing data from 3D to 2D Garbin Microsoft Excel Worksheet Functions 7 5th Dec 2007 06:29 PM
Need help condensing with-end with code excelnut1954 Microsoft Excel Programming 2 1st May 2006 03:49 PM
Condensing lists =?Utf-8?B?c2t5d2Fsa2VyOTQ5NDk0?= Microsoft Excel Worksheet Functions 1 6th Jul 2005 03:14 PM
Condensing =?Utf-8?B?TWFyYw==?= Windows XP MovieMaker 0 9th Feb 2004 08:31 AM


Features
 

Advertising
 

Newsgroups
 


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