Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Creating and using an array

Hi everyone,

I have a section of code which repeats with minimal changes ( 2 items per
repeat)

These two items represent the original column copied and the column it is
copying to.

Is there any way I could simplify my code using an array and looping through
it?

Thanks for the help,

John


My original code is as follows:

Worksheets(2).Select
Columns("X:X").Clear
Worksheets(2).Range("P1:P" & lastrow).AdvancedFilter
Action:=xlFilterCopy, _
CopyToRange:=Range("X1"), Unique:=True
Columns("X:X").Select
Selection.Sort Key1:=Range("X2"), Order1:=xlAscending, Header:=xlYes
Selection.Copy
Sheets("Menu").Select
Columns("I:I").PasteSpecial Paste:=xlPasteValues

Worksheets(2).Select
Columns("X:X").Clear
Worksheets(2).Range("A1:A" & lastrow).Select
Selection.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("X1"), Unique:=True
Columns("X:X").Select
Selection.Sort Key1:=Range("X2"), Order1:=xlAscending, Header:=xlYes
Selection.Copy
Sheets("Menu").Select
Columns("J:J").PasteSpecial Paste:=xlPasteValues


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Creating and using an array

Is this any better for you

CopyData Worksheets(2).Range("P1"), Worksheets("Menu").Range("I:I")
CopyData Worksheets(2).Range("A1"), Worksheets("Menu").Range("J:J")

'...

Sub CopyData(StartCell As Range, Target As Range)
With Worksheets(2)
.Select
.Columns("X:X").Clear
StartCell.Resize(lastrow).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("X1"), _
Unique:=True
With .Columns("X:X")
.Sort Key1:=Range("X2"), Order1:=xlAscending, Header:=xlYes
.Copy
End If
End With
Sheets("Menu").Select
Target.PasteSpecial Paste:=xlPasteValues
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"John Ortt" wrote in message
...
Hi everyone,

I have a section of code which repeats with minimal changes ( 2 items per
repeat)

These two items represent the original column copied and the column it is
copying to.

Is there any way I could simplify my code using an array and looping

through
it?

Thanks for the help,

John


My original code is as follows:

Worksheets(2).Select
Columns("X:X").Clear
Worksheets(2).Range("P1:P" & lastrow).AdvancedFilter
Action:=xlFilterCopy, _
CopyToRange:=Range("X1"), Unique:=True
Columns("X:X").Select
Selection.Sort Key1:=Range("X2"), Order1:=xlAscending, Header:=xlYes
Selection.Copy
Sheets("Menu").Select
Columns("I:I").PasteSpecial Paste:=xlPasteValues

Worksheets(2).Select
Columns("X:X").Clear
Worksheets(2).Range("A1:A" & lastrow).Select
Selection.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("X1"), Unique:=True
Columns("X:X").Select
Selection.Sort Key1:=Range("X2"), Order1:=xlAscending, Header:=xlYes
Selection.Copy
Sheets("Menu").Select
Columns("J:J").PasteSpecial Paste:=xlPasteValues




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Creating and using an array

Far better,

Thanks Bob.


"Bob Phillips" wrote in message
...
Is this any better for you

CopyData Worksheets(2).Range("P1"), Worksheets("Menu").Range("I:I")
CopyData Worksheets(2).Range("A1"), Worksheets("Menu").Range("J:J")

'...



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
creating an array Richard New Users to Excel 4 March 15th 07 01:06 PM
creating an array Richard Excel Worksheet Functions 4 March 15th 07 01:06 PM
creating an array from range help Gary Keramidas Excel Programming 5 August 13th 06 02:48 AM
creating an array on the fly Gary Keramidas Excel Programming 4 August 9th 06 09:34 PM
Creating an array Eric[_6_] Excel Programming 1 January 12th 04 08:25 PM


All times are GMT +1. The time now is 02:59 AM.

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

About Us

"It's about Microsoft Excel"