Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Search for empty cells and move cells next to | Excel Programming | |||
Move cells down to match cells | Excel Programming | |||
Move cells down to match cells | Excel Programming | |||
Can references (to cells being sorted) move with the cells? | Setting up and Configuration of Excel | |||
Sorting cells: a list behind the cells do not move with the cell | Excel Discussion (Misc queries) |