Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default define Range in vba using contents of a cell that is named

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....
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default define Range in vba using contents of a cell that is named

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
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
How do I have a cell value define a dynamic named range? CellShocked Excel Worksheet Functions 15 October 26th 11 02:08 AM
Hyperlink to Named Range Based On Cell Contents TKS_Mark Excel Worksheet Functions 1 January 9th 08 04:14 PM
RE Define Named Range. DeveloperSQL Excel Programming 3 April 18th 07 10:52 PM
Goto a named range using the contents of the active cell Brian C Excel Programming 1 June 14th 06 05:14 AM
How to define a Named Range in VBA? Richard Excel Programming 3 December 12th 05 06:49 PM


All times are GMT +1. The time now is 04:06 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"