Dynamic Range

Aviles

Board Regular
Joined
Dec 17, 2008
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Hello

I have found the below code which uses range C2:C20.

Can some one please tell me how to increase this range, eg C2:C100?

Code:
Private Sub Worksheet_SelectionChange _
(ByVal Target As Range)
Dim r As Long
Dim wsL As Worksheet
Set wsL = Worksheets("Lists")
If Target.Count > 1 Then Exit Sub
If Target.Column = 3 And Target.Row > 2 Then
wsL.Range("A1").CurrentRegion.ClearContents
Range(Cells(2, 3), Cells(Target.Row - 1, 3)) _
.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=wsL.Range("A1"), Unique:=True
r = wsL.Cells(Rows.Count, 1).End(xlUp).Row
wsL.Range(wsL.Cells(1, 1), wsL.Cells(r, 1)).Sort _
Key1:=wsL.Range("A1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
ActiveWorkbook.Names.Add Name:="DataValList", _
RefersToR1C1:="=Lists!R1C1:R" & r & "C1"
With Target.Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:="=DataValList"
.IgnoreBlank = True
.InCellDropdown = True
.ShowError = False
End With
End If
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
What makes you say that? I see no such range specification.

The website that I got it from said that it was only used for range C2:C20. I also tried the code which confirms it.

I'm with you, can't see any range specification anywhere.
 
Upvote 0
The website that I got it from said that it was only used for range C2:C20. I also tried the code which confirms it.

I'm with you, can't see any range specification anywhere.

Can you say what tests you tried with the code ... what data you put in, and what happened when you ran it, and what you think should have happened if there was no range limitation?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top