Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default how to change the range

Hi,

The first two lines of this code are currently hardcoded for a dataset
which has the range exactly of A1:I2754 and a criterial dataset which
has a range of A1:G5.

I`ve seen in another message about set rng =
activesheet.range("A1").currentregion.
But am new to VB and not sure how to do this.
How could the following code be adjusted so that it automatically takes
the full range of the datasets which contains data (no matter the size),
and the same for the criteria dataset?

David Shapiro

Sheets("source data").Select
Range("A1:I2754").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:= _
Sheets("criteria").Range("A1:G5"), Unique:=False

Sheets.add
Sheets("source data").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Sheet1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
End Sub


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default how to change the range

Hi David,

Try:

Dim rng1 As Range, rng2 As Range

With Sheets("source data")
Set rng1 = .Range(.Range("A1"), _
.Cells(Rows.Count, "A").End(xlUp))
End With

With Sheets("criteria")
Set rng2 = Range(.Range("A1"), _
.Cells(1, Columns.Count).End(xlToLeft))
End With


---
Regards,
Norman



"david shapiro" wrote in message
...
Hi,

The first two lines of this code are currently hardcoded for a dataset
which has the range exactly of A1:I2754 and a criterial dataset which
has a range of A1:G5.

I`ve seen in another message about set rng =
activesheet.range("A1").currentregion.
But am new to VB and not sure how to do this.
How could the following code be adjusted so that it automatically takes
the full range of the datasets which contains data (no matter the size),
and the same for the criteria dataset?

David Shapiro

Sheets("source data").Select
Range("A1:I2754").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:= _
Sheets("criteria").Range("A1:G5"), Unique:=False

Sheets.add
Sheets("source data").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Sheet1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
End Sub


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default how to change the range

Norman,

Thanks for the suggestion. How would it work though with an advanced
filter command such as:

Sheets("source data").Select
Range("A1:I2754").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:= _
Sheets("criteria").Range("A1:G5"), Unique:=False


How do I incorporate the range codes you mentioned in that?

Dave



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default how to change the range

Hi David,

Something like this may work for you:

Sub Tester01()
Dim rngData As Range, RngCrit As Range
Dim rngOutput As Range

With ActiveWorkbook
With .Sheets("Source Data")
Set rngData = .Range("A1").CurrentRegion '<<CHANGE
End With

With .Sheets("Output")
Set RngCrit = .Range("H1").CurrentRegion '<<CHANGE
Set rngOutput = .Range("A1") '<<CHANGE
End With

.Sheets("Output").Activate
rngData.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=RngCrit, _
CopyToRange:=rngOutput, _
Unique:=True
End With
End Sub

Amend the sheet names and ranges to suit your needs.


---
Regards,
Norman



"david shapiro" wrote in message
...
Norman,

Thanks for the suggestion. How would it work though with an advanced
filter command such as:

Sheets("source data").Select
Range("A1:I2754").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:= _
Sheets("criteria").Range("A1:G5"), Unique:=False


How do I incorporate the range codes you mentioned in that?

Dave



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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 can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
How do I change a range name back to the underlying data range? Colin Excel Worksheet Functions 1 September 26th 05 05:55 PM
How do I change the range? sonar Excel Worksheet Functions 2 September 3rd 05 11:26 AM
Change range name Al Eaton Excel Programming 1 July 26th 04 03:38 AM
how to change range in VBA? Nazrul Excel Programming 2 October 18th 03 03:29 PM


All times are GMT +1. The time now is 03:41 PM.

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"