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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

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