ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using variable for range address (https://www.excelbanter.com/excel-programming/362303-using-variable-range-address.html)

dr chuck

Using variable for range address
 


If Range("h9").Value = "N" Then
Selection.AutoFilter Field:=1, Criteria1:="+"
End If

I want to be able to replace "h9" with a variable that i can change
frequently. (ie h9, j12,or whatever cell address i want to use).

I have tried ....
Dim Ant string
Ant = "h9"
If Range("Ant").Value = "N" Then
Selection.AutoFilter Field:=1, Criteria1:="+"
End If

This however does not work. I am not sure of the proper syntax to achieve
this goal.


Thanks in advance--
dr chuck

[email protected]

Using variable for range address
 
take the quotes away from ANT - with quotes, you are referring to a
named range ANT, without you are referring to the variable - so

if range(ant).value etc


Ardus Petus

Using variable for range address
 
Dim Ant as String
Ant="H9"
if range(Ant).value="N" then

HTH
--
AP

"dr chuck" a écrit dans le message de
news: ...


If Range("h9").Value = "N" Then
Selection.AutoFilter Field:=1, Criteria1:="+"
End If

I want to be able to replace "h9" with a variable that i can change
frequently. (ie h9, j12,or whatever cell address i want to use).

I have tried ....
Dim Ant string
Ant = "h9"
If Range("Ant").Value = "N" Then
Selection.AutoFilter Field:=1, Criteria1:="+"
End If

This however does not work. I am not sure of the proper syntax to achieve
this goal.


Thanks in advance--
dr chuck




Crowbar via OfficeKB.com

Using variable for range address
 
Remove the ""

Dim Ant string
Ant = "h9"
If Range(Ant).Value = "N" Then
Selection.AutoFilter Field:=1, Criteria1:="+"
End If




--
Message posted via
http://www.officekb.com

dr chuck

Using variable for range address
 
thanks guys .. for the immediate help

--
dr chuck


"Crowbar via OfficeKB.com" wrote:

Remove the ""

Dim Ant string
Ant = "h9"
If Range(Ant).Value = "N" Then
Selection.AutoFilter Field:=1, Criteria1:="+"
End If




--
Message posted via
http://www.officekb.com



All times are GMT +1. The time now is 01:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com