![]() |
select the range with the cell's position is a variable.
can anyone tell me how to select a range which will keep changing? for
eg: Sub select_range() Dim abc As Range Dim a As Integer Dim b As Integer a = 2 + 2 b = 2 abc = Range("ab") abc.Select End Sub How to modify the code if i wish to make the a, b as a variable? |
select the range with the cell's position is a variable.
Hi youu917;
You can create a function and pass the values to it something like this: Sub ExampleOfCallingMyFunction varFirstRow = 1 varMyFirstColumn = 1 varMyLastRow = 10 varMyLastColumn = 2 GoSelectMyRange varFirstRow, varMyFirstColumn, varMyLastRow, varMyLastColumn End Sub Function GoSelectMyRange (varFirstRow, varMyFirstColumn, varMyLastRow, varMyLastColumn) Range(Cells(varFirstRow,varMyFirstColumn), Cells(varMyLastRow, varMyLastColumn)).Select End Function I Hope This Helps " wrote: can anyone tell me how to select a range which will keep changing? for eg: Sub select_range() Dim abc As Range Dim a As Integer Dim b As Integer a = 2 + 2 b = 2 abc = Range("ab") abc.Select End Sub How to modify the code if i wish to make the a, b as a variable? |
select the range with the cell's position is a variable.
On Mar 14, 10:29*am, DownThePaint
wrote: Hi youu917; You can create a function and pass the values to it something like this: Sub ExampleOfCallingMyFunction * * *varFirstRow = 1 * * *varMyFirstColumn = 1 * * *varMyLastRow = 10 * * *varMyLastColumn = 2 * * *GoSelectMyRange varFirstRow, varMyFirstColumn, varMyLastRow, varMyLastColumn End Sub Function *GoSelectMyRange (varFirstRow, varMyFirstColumn, varMyLastRow, varMyLastColumn) * * *Range(Cells(varFirstRow,varMyFirstColumn), Cells(varMyLastRow, varMyLastColumn)).Select End Function I Hope This Helps " wrote: can anyone tell me how to select a range which will keep changing? for eg: Sub select_range() Dim abc As Range Dim a As Integer Dim b As Integer a = 2 + 2 b = 2 abc = Range("ab") abc.Select End Sub How to modify the code if i wish to make the a, b as a variable?- Hide quoted text - - Show quoted text - Thank you very much |
All times are GMT +1. The time now is 08:48 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com