Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default use variable value in a range reference?

My code is

Dim myformulaTotalRows As Integer
Dim mylastFormulaRow As Integer

With Range("formulaCells") 'named range
totalRows = .Rows.Count
lastRow = .Rows(totalRows).Row
End With

myformulaTotalRows = totalRows
mylastFormulaRow = lastRow

Is there a way to use "mylastFormulaRow" in a statement like
Range("C6").select where the row number 6 can be replaced by
"mylastFormulaRow"?

I want to use the selected cell as the first argument in a .filldown statement

Thanks for any help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default use variable value in a range reference?

Range("C" & mylastformularow).select
or
cells(mylastformularow, "C").select



JCIrish wrote:

My code is

Dim myformulaTotalRows As Integer
Dim mylastFormulaRow As Integer

With Range("formulaCells") 'named range
totalRows = .Rows.Count
lastRow = .Rows(totalRows).Row
End With

myformulaTotalRows = totalRows
mylastFormulaRow = lastRow

Is there a way to use "mylastFormulaRow" in a statement like
Range("C6").select where the row number 6 can be replaced by
"mylastFormulaRow"?

I want to use the selected cell as the first argument in a .filldown statement

Thanks for any help


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default use variable value in a range reference?

Thanks, Dave. I must have tried ten things similar to your solution except
including the &. I appreciate the help.

"Dave Peterson" wrote:

Range("C" & mylastformularow).select
or
cells(mylastformularow, "C").select



JCIrish wrote:

My code is

Dim myformulaTotalRows As Integer
Dim mylastFormulaRow As Integer

With Range("formulaCells") 'named range
totalRows = .Rows.Count
lastRow = .Rows(totalRows).Row
End With

myformulaTotalRows = totalRows
mylastFormulaRow = lastRow

Is there a way to use "mylastFormulaRow" in a statement like
Range("C6").select where the row number 6 can be replaced by
"mylastFormulaRow"?

I want to use the selected cell as the first argument in a .filldown statement

Thanks for any help


--

Dave Peterson
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default use variable value in a range reference?

Thank you,Don. That's a more elegant way to go than my Sub. I'm sure it will
be useful to me in many similar situations.

"Don Guillett" wrote:

Sub fillitdown()
'Range("e1").AutoFill Range("e1:e4")
dim lr as long
lr = Cells(Rows.Count, "e").End(xlUp).Row
Cells(lr, "e").AutoFill Cells(lr, "e").Resize(4)
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"JCIrish" wrote in message
...
My code is

Dim myformulaTotalRows As Integer
Dim mylastFormulaRow As Integer

With Range("formulaCells") 'named range
totalRows = .Rows.Count
lastRow = .Rows(totalRows).Row
End With

myformulaTotalRows = totalRows
mylastFormulaRow = lastRow

Is there a way to use "mylastFormulaRow" in a statement like
Range("C6").select where the row number 6 can be replaced by
"mylastFormulaRow"?

I want to use the selected cell as the first argument in a .filldown
statement

Thanks for any help


.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reference variable range? WhatsUp31415 Excel Discussion (Misc queries) 4 May 17th 09 07:20 PM
Use variable to reference a range? RITCHI Excel Programming 1 January 10th 07 07:04 PM
How do I set up a variable reference range in Excel? Pecan1862 Excel Programming 1 January 27th 06 09:29 PM
Variable range reference Kyle Szukaitis Excel Discussion (Misc queries) 1 October 21st 05 03:10 AM
Variable Range Reference Bob Excel Programming 3 December 16th 04 04:13 PM


All times are GMT +1. The time now is 07:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"