View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Nick Hodge Nick Hodge is offline
external usenet poster
 
Posts: 1,173
Default Loop through columns and then rows

Iterations are often simpler if you pre-select the data. If this is
possible the code below will run along the rows and then down the columns
changing what is in the cell to only the first three characters.

If you cannot pre-select, post back

Sub IterateSelection()
Dim myCell As Range
For Each myCell In Selection
myCell.Value = Left(myCell.Value, 3)
Next myCell
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Sunryzz" wrote in message
...
I have a spreadsheet that needs the text in 2 columns to be altered. I
would
like to do the whole spreadsheet with a macro and the number of rows
changes.
I have set up a macro that works if I click in the top cell of each
column,
but I would like to be able to click in the first cell and have it fix
that
cell and then go to the next column and fix it, next column and fix it,
etc
until it reaches the end of the row. Then it would need to move down to
the
next row and do the same thing. It would do this until it encountered a
blank row. The task necessary to fix the cell is not one where I can
highlight the whole row; it only works on a single cell at a time. Does
anyone have a good bit of code that would work well for this application?
Thanks so much!