ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assigning a cell address to a variable (https://www.excelbanter.com/excel-programming/439470-assigning-cell-address-variable.html)

James

Assigning a cell address to a variable
 
I'm sure this is a simple question, but I've been searching and cannot seem
to find the answer to it. I have a couple of loops that run that put data
onto a spreadsheet, I want to before the loop runs assign a variable the
address of the first cell and at the end assign a variable the address of the
last cell. I am trying to use

Set LastDay = Range(Cells(3, CalCount))

but this gives me an error. Any ideas or help I would love.

Thanks

Mike H

Assigning a cell address to a variable
 
James,

This would set the variable LastDay to the address of the last used cell in
column A and then create a named range from A1 to that cell


LastDay = "A" & Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:" & LastDay)

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"James" wrote:

I'm sure this is a simple question, but I've been searching and cannot seem
to find the answer to it. I have a couple of loops that run that put data
onto a spreadsheet, I want to before the loop runs assign a variable the
address of the first cell and at the end assign a variable the address of the
last cell. I am trying to use

Set LastDay = Range(Cells(3, CalCount))

but this gives me an error. Any ideas or help I would love.

Thanks



All times are GMT +1. The time now is 08:49 PM.

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