How to Select A Cell in VBA with a Variable Row Number?
Here are examples of normal VBA with no variables that works:
Range("K20").Select Range("K20").Activate I want to replace the 20 (meaning row 20) with a variable from a named cell. For example, I named cell Z100 as "XRow". XRow now contains the number 7, which can change any time according to formula. I want the VBA to say something like one of the following, but I can't get it to work: Range("KXrow").Select Range("K"Xrow"").Select Range(Cells(K,Xrow)).Select Range(Cells(K,"Xrow")).Select If necessary, I could make do with an unnamed cell, so that it could look something like Range("KZ100").Select Range("K"Z100"").Select Range(Cells(K,Z100)).Select Range(Cells(K,"Z100")).Select Any ideas? Thanks! |
Answer: How to Select A Cell in VBA with a Variable Row Number?
Formula:
Code:
Range("Z100").Value Next, we use the Code:
Range("K" & XRow).Select To select a cell in VBA with a variable row number, you can follow these steps:
|
How to Select A Cell in VBA with a Variable Row Number?
Dim lngRow as Long
lngRow = Range("XRow").Value Range("K" & lngRow).Select -or- Cells(11, lngRow).Select -- Jim Cone Portland, Oregon USA http://www.mediafire.com/PrimitiveSoftware (Extras for Excel: Date picker, Clean Data, Classic Menu ...) "David Godinger" wrote in message news:20912655.1748.1332623461737.JavaMail.geo-discussion-forums@pbtd1... Here are examples of normal VBA with no variables that works: Range("K20").Select Range("K20").Activate I want to replace the 20 (meaning row 20) with a variable from a named cell. For example, I named cell Z100 as "XRow". XRow now contains the number 7, which can change any time according to formula. I want the VBA to say something like one of the following, but I can't get it to work: Range("KXrow").Select Range("K"Xrow"").Select Range(Cells(K,Xrow)).Select Range(Cells(K,"Xrow")).Select If necessary, I could make do with an unnamed cell, so that it could look something like Range("KZ100").Select Range("K"Z100"").Select Range(Cells(K,Z100)).Select Range(Cells(K,"Z100")).Select Any ideas? Thanks! |
How to Select A Cell in VBA with a Variable Row Number?
Works great! Nice and simple.
Thanks! On Saturday, March 24, 2012 3:33:30 PM UTC-7, Jim Cone wrote: Dim lngRow as Long lngRow = Range("XRow").Value Range("K" & lngRow).Select -or- Cells(11, lngRow).Select |
How to Select A Cell in VBA with a Variable Row Number?
On Sat, 24 Mar 2012, Jim Cone wrote:
Dim lngRow as Long lngRow = Range("XRow").Value Range("K" & lngRow).Select -or- Cells(11, lngRow).Select It can be even simpler. Like: Range("K" & Range("XRow").Value).Select -or- Cells(11, Range("XRow").Value).Select Don. www.donwiss.com (e-mail link at home page bottom). |
All times are GMT +1. The time now is 11:26 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com