PC Review


Reply
Thread Tools Rate Thread

define Range in vba using contents of a cell that is named

 
 
Brotherharry
Guest
Posts: n/a
 
      13th Feb 2009
I'm writing a macro which will autofilter, copy and paste data
depending on values entered into certain cells

e.g.
cell A1, named 'lastrow', has the last row number of the available
data e.g. 468
cell A2 has the last column e.g. AM
cell A3 named 'mydatarange', contains a text string built using
concatenate e.g. $A$1:$AM:$468

in the macro, it should run the autofilter as below (illustrated with
fixed range data)

Sheets("MyRawData").Select
Range("A1").Select
ActiveSheet.Range("$A$1:$AM:$468").AutoFilter Field:=29,
Criteria1:= _
"pending"
Rows("1:465").Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Pending"
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False


What I'm aiming for however is something like the below

Sheets("MyRawData").Select
Range("A1").Select
ActiveSheet.Range("mydatarange").AutoFilter Field:=29, Criteria1:=
_
"pending"
Rows("1:" & lastrow).Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Pending"
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False


Hoping it's just a syntax knowledge shortfall....
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      13th Feb 2009
Is this what you are looking for?

Range("A3").Name = "mydatarange"
Range("mydatarange") = _
Range("$A$1:" & Range("A2").Value & Range("A1").Value)

Which should come out to
Range("mydatarange") = Range("A1:AM468")

"Brotherharry" wrote:

> I'm writing a macro which will autofilter, copy and paste data
> depending on values entered into certain cells
>
> e.g.
> cell A1, named 'lastrow', has the last row number of the available
> data e.g. 468
> cell A2 has the last column e.g. AM
> cell A3 named 'mydatarange', contains a text string built using
> concatenate e.g. $A$1:$AM:$468
>
> in the macro, it should run the autofilter as below (illustrated with
> fixed range data)
>
> Sheets("MyRawData").Select
> Range("A1").Select
> ActiveSheet.Range("$A$1:$AM:$468").AutoFilter Field:=29,
> Criteria1:= _
> "pending"
> Rows("1:465").Select
> Selection.Copy
> Sheets.Add After:=Sheets(Sheets.Count)
> Sheets("Sheet1").Select
> Sheets("Sheet1").Name = "Pending"
> Range("A1").Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
> SkipBlanks:=False, Transpose:=False
>
>
> What I'm aiming for however is something like the below
>
> Sheets("MyRawData").Select
> Range("A1").Select
> ActiveSheet.Range("mydatarange").AutoFilter Field:=29, Criteria1:=
> _
> "pending"
> Rows("1:" & lastrow).Select
> Selection.Copy
> Sheets.Add After:=Sheets(Sheets.Count)
> Sheets("Sheet1").Select
> Sheets("Sheet1").Name = "Pending"
> Range("A1").Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
> SkipBlanks:=False, Transpose:=False
>
>
> Hoping it's just a syntax knowledge shortfall....
>

 
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
Hyperlink to Named Range Based On Cell Contents TKS_Mark Microsoft Excel Worksheet Functions 1 9th Jan 2008 04:14 PM
RE Define Named Range. =?Utf-8?B?RGV2ZWxvcGVyU1FM?= Microsoft Excel Programming 3 18th Apr 2007 10:52 PM
Define Named Range Abdul Microsoft Excel Programming 1 30th Aug 2006 06:11 PM
Goto a named range using the contents of the active cell =?Utf-8?B?QnJpYW4gQw==?= Microsoft Excel Programming 1 14th Jun 2006 05:14 AM
How to define a Named Range in VBA? =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Programming 3 12th Dec 2005 06:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:00 PM.