LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default MOVE CELLS DOWN

gary c wrote:

On Dec 24, 1:23*pm, "Auric__" wrote:
gary c wrote:
How can I move the cells in COL A down so their RIGHT 7 characters
are on the same row as the matching LEFT 7 characters in COL B?


This works with the specific data you posted:


[snip code]

Test with test data BEFORE using live. (Make a copy of your data and
test on *that*.)


What happens if a match is not found? (Is there an error-message, a
blank line or ????),


You mean no matches at all? Then all the data in A gets moved below the
data in B. So if there are, say, 5 items in B2:B6, then A2:A6 is empty and
the data in A starts on A7, like this:
A B
2 data
3 data
4 data
5 data
6 data
7 data
8 data
9 data
10 data
11 data

If you *want* some sort of indicator, you just add a flag (the new variable
"found" here):
Sub lineup()
Dim found As Boolean
Dim check As String, against As String
Dim r1 As Long, r2 As Long
r1 = 1
stoprow = Cells.SpecialCells(xlCellTypeLastCell).Row
looper:
check = Right$(Cells(r1, 1).Value, 7)
Application.StatusBar = "row " & r1
For r2 = r1 To Cells.SpecialCells(xlCellTypeLastCell).Row
against = Left$(Cells(r2, 2).Value, 7)
If (r2 stoprow) Then GoTo done
If (check) = against Then found = True: Exit For
Cells(r2, 1).Insert Shift:=xlDown
Cells(r2 + 1, 1).Select
DoEvents
Next
r1 = r2 + 1
GoTo looper
done:
If Not found Then MsgBox "No matches found!"
Application.StatusBar = Null
End Sub

This still does as I mentioned above, moving all of A below B's data. (To
avoid that, you'd need to separate the scanning and the inserting.)

--
- Louise, be subtle.
- Louise is as subtle as a lead pipe.
 
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
Search for empty cells and move cells next to KP[_4_] Excel Programming 10 September 21st 11 08:44 PM
Move cells down to match cells gcotterl[_2_] Excel Programming 3 April 1st 10 06:54 PM
Move cells down to match cells gcotterl[_2_] Excel Programming 0 March 31st 10 10:34 PM
Can references (to cells being sorted) move with the cells? Zack Setting up and Configuration of Excel 1 January 16th 08 01:50 PM
Sorting cells: a list behind the cells do not move with the cell Ross M Excel Discussion (Misc queries) 2 September 21st 06 12:14 PM


All times are GMT +1. The time now is 09:01 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"