macro to edit cell contents

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to edit a cell's contents by insert at ^ and the beginning and end of
what ever is in the cell, then move down to the next cell to be ready for the
next one.

Macro recorder can't seem to handle this.

Thanks.
 
If I understand correctly, you'd like to insert a carat symbol at the
beginning and end of the contents of a cell (e.g., "harry" becomes "^harry^")
and then keep moving down the list of items and editing each one in the same
way until you run out of items. If that's what you want to do, then perhaps
this helps (you'll need to set focus on the first item in the list that you
want to edit and I'm assuming that you have no blanks in your list):

Sub EditCells()
Dim i As Integer
Do Until ActiveCell.Value = ""
ActiveCell.Value = "^" & ActiveCell.Value & "^"
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
here's one way, assuming your values start in a1 and are in 1 column

Sub test()
Dim lastrow As Long, cell As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In Range("A1:A" & lastrow)
cell.Value = "^" & cell.Value & "^"
Next
End Sub
 
Thanks everyone, worked great.
--
Alan


Gary Keramidas said:
here's one way, assuming your values start in a1 and are in 1 column

Sub test()
Dim lastrow As Long, cell As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In Range("A1:A" & lastrow)
cell.Value = "^" & cell.Value & "^"
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top