select the range with the cell's position is a variable.

  • Thread starter Thread starter youu917
  • Start date Start date
Y

youu917

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?
 
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
 
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








- Show quoted text -

Thank you very much
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top