Excel: Automating the Selection of an Unknown Number of Cells

Posted by user1905080 on Stack Overflow See other posts from Stack Overflow or by user1905080
Published on 2012-12-14T20:14:40Z Indexed on 2012/12/14 23:04 UTC
Read the original article Hit count: 156

Filed under:
|
|

I’m trying to automate the formatting of an excel file by a macro and am seeking a solution.

I have two columns titled Last Name and First Name which I would like to concatenate into a separate column titled Last Name, First Name.

This is simple enough when done by hand: create one cell which does this, then drag that cell to include all cells within the range. The problem appears when trying to automate this. Because I can’t know the number of names that need to be concatenated ahead of time, I can’t automate the selection of cells by dragging.

Can you help me automate this?

I’ve tried a process of copying the initial concatenated cell, highlighting the column, and then pasting. I’ve also tried to use a formula which returned the concatenation only if there is text in the “Last Name” and “First Name” columns. However, in both cases, I end up with some 100,000 rows, putting a serious cramp on my ability to manipulate the worksheet.

The best solution I can think of is to create concatenations within a fixed range of cells. Although this would create useless cells, at least there wouldn’t be 99,900 of them.

© Stack Overflow or respective owner

Related posts about excel

Related posts about vba