LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
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!



 
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
loop over columns kizzie Excel Discussion (Misc queries) 4 August 10th 05 01:31 PM
loop through columns hotherps[_78_] Excel Programming 6 July 23rd 04 11:40 AM
Loop 20 columns Help! Michael168[_106_] Excel Programming 2 July 2nd 04 12:26 PM
Cannot loop through rows in C# Howard Excel Programming 2 February 5th 04 03:39 PM
How do I delete rows and columns in With With End Loop? Bob Benjamin Excel Programming 3 November 16th 03 12:26 AM


All times are GMT +1. The time now is 06:03 PM.

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"