Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Operating on a Selected Range

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Operating on a Selected Range

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Operating on a Selected Range

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Operating on a Selected Range

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
operating over a range in an array ghengis_na'an Excel Discussion (Misc queries) 1 October 7th 09 06:27 PM
How to write (Selected range - 1) Damian Excel Discussion (Misc queries) 2 September 4th 09 08:20 PM
Appearance of a selected range d_mack Excel Discussion (Misc queries) 10 October 5th 07 12:31 AM
Copying a selected used range michael Excel Programming 1 September 24th 03 02:49 PM
Box around selected range Tom Ogilvy Excel Programming 1 September 7th 03 04:42 PM


All times are GMT +1. The time now is 10:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"