macro for inserting text


Posted by Dan Frantz on August 26, 2001 6:55 AM

I have been trying to write a macro that can append a set of characters (text) to the start of text contained within the cells of a given column. The cells within the column all contain different text characters (words), and what I need to do is add the characters "cat" to the start of contents of each cell without otherwise changing the cell contents. Can anyone help?

Thanks



Posted by Damon Ostrander on August 26, 2001 6:07 PM

Hi Dan,

Here's the code for column B:

Dim LastRow As Long
Dim iRow As Long

LastRow = [B65536].End(xlUp).Row

For iRow = 2 To LastRow

Cells(iRow, 2).Value = "cat" & Cells(iRow, 2).Value

Next iRow


Note that it starts at row 2 assuming row 1 contains a heading, and goes until it hits the last cell containing data in column B (column 2). It always operates on the active worksheet.

Happy computing.

Damon