How to Dim a variable as a Cell?

On Excel, I'm trying to code a macro that involves selecting a range of cells, in which both the upper limit and the lower limit cells in the range are variables. How would I go about programming this?

More specifically:

I have a column A and a column B. I wish to select a range of cells from column A and merge them together. That range will be equal to the range of cells in column B that are NOT empty. So, for example:

If cells B1 to B15 aren't empty (and B16 is empty), then my macro will select the cells A1 to A15 (then merge them).

2011-03-27T22:22:42Z

garbo: It's for use in a database, for quicker formatting. There won't be any text in the cells to merge. I'd really appreciate it if you can tell me how to code it.

Anonymous2011-03-27T10:27:54Z

Favorite Answer

You cannot do it as a Cell. You can do it as a Range.

Dim c As Range
Set c = Range("A1")
c.Value = "AA"

.

garbo74412011-03-27T17:37:34Z

This is fairly easily accomplished with a macro. However, if your selected cells each contain a value your merged result will contain only the value in the first cell in the selected range.

I am curious what your goal is in achieving that result.