Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
We have a macro that indents and inserts a hyphen onto
text, i.e., "Johnson" becomes " - Johnson". We would like the macro rather than operate on a single cell to cycle through each cell in the selected range. I am also curious to know what Visual Basic method moves the active cursor down one cell. Thank you for the help. Kevin Sprinkel Becker & Frondorf |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
ActiveCell.Offset(1,0).Select
but you don't need to do that to work with a cell Sub AddHyphen() Dim cell as Range for each cell in Selection if not cell.hasFormula then if instr(cell.value,"-") = 0 then cell.Value = "- " & cell.Value End if End if Next End Sub -- Regards, Tom Ogilvy "Kevin Sprinkel" wrote in message ... We have a macro that indents and inserts a hyphen onto text, i.e., "Johnson" becomes " - Johnson". We would like the macro rather than operate on a single cell to cycle through each cell in the selected range. I am also curious to know what Visual Basic method moves the active cursor down one cell. Thank you for the help. Kevin Sprinkel Becker & Frondorf |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, Tom. That's exactly what we were looking for.
Best Regards. Sub AddHyphen() Dim cell as Range for each cell in Selection if not cell.hasFormula then if instr(cell.value,"-") = 0 then cell.Value = "- " & cell.Value End if End if Next End Sub -- Regards, Tom Ogilvy |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
To cycle through cells, you can try the For Next
convention. For example, For Each c In Range(RefEdit1.Value).Cells c.Value = "'" & c.Value Next c is a variable in the above code. To move the cursor down one, you can try SendKeys "{Down}", True 'Moves the cursor down to the next cell Hope this helps. Keith Lorenzen -----Original Message----- We have a macro that indents and inserts a hyphen onto text, i.e., "Johnson" becomes " - Johnson". We would like the macro rather than operate on a single cell to cycle through each cell in the selected range. I am also curious to know what Visual Basic method moves the active cursor down one cell. Thank you for the help. Kevin Sprinkel Becker & Frondorf . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
operating over a range in an array | Excel Discussion (Misc queries) | |||
How to write (Selected range - 1) | Excel Discussion (Misc queries) | |||
Appearance of a selected range | Excel Discussion (Misc queries) | |||
Copying a selected used range | Excel Programming | |||
Box around selected range | Excel Programming |