how to set dynamic range with this code?

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
Code:
Sub test()
Dim f As String
Dim ab As String

 text= ThisWorkbook.Worksheets("Sheet1").Range("F1").Value
filter = ThisWorkbook.Worksheets("Sheet1").Range("AB1").Value

If text = filter Then
  ThisWorkbook.Worksheets("Sheet1").Range("S1").Value = "xxxx"
End If

End Sub


I have code like that, but I would like to setup dynamic range for filter, text and validation column (column S).
Is there any way to make dynamic range with this code?

Thank you!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Using variables is the way to go to ID those values at runtime. Assuming the beginning of the range will always be known (not dynamic), you would use something like this to ID the last used row in a particular column (column 1 or A in this example):
Code:
Dim finalRow As Integer

finalRow = Cells(Rows.Count, [COLOR=#0000FF]1[/COLOR]).End(xlUp).Row

If the number of columns is dynamic, you would just shuffle that syntax around to find the last used column in a particular row:
Code:
Dim finalCol As Integer

finalCol = Cells(1, Columns.Count).End(xlToLeft).Column
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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