ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro to edit cell contents (https://www.excelbanter.com/excel-programming/375128-macro-edit-cell-contents.html)

adgorn

macro to edit cell contents
 
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.
--
Alan

Paul Mathews

macro to edit cell contents
 
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


"adgorn" wrote:

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.
--
Alan


Gary Keramidas

macro to edit cell contents
 
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


--


Gary


"adgorn" wrote in message
...
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.
--
Alan




Paul Mathews

macro to edit cell contents
 
Sorry, you can delete the declaration of i (dim i as integer) in the code
below).

"Paul Mathews" wrote:

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


"adgorn" wrote:

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.
--
Alan


adgorn

macro to edit cell contents
 
Thanks everyone, worked great.
--
Alan


"Gary Keramidas" wrote:

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


--


Gary


"adgorn" wrote in message
...
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.
--
Alan






All times are GMT +1. The time now is 10:18 PM.

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