I have a 3 column worksheet, that two columns need to be matched and a space added if no match, and the 3rd column is tied into the 2nd column, and needs to stay with it if moved. I have searched for something like this, and only found one with the 2 column align and match. Here's the code for the 2 column one, and I need it to take the 3rd column and tie it too the 2nd and move that one as well when any column moves. Here is the code I already have:
[code]
Option Explicit
Sub Isolate()
Dim lastA, lastB, shortCol, rw As Integer
'Determine short column so we know when to stop
lastA = WorksheetFunction.CountA(Range("A:A"))
lastB = WorksheetFunction.CountA(Range("B:B"))
If lastA > lastB Then _
shortCol = 2 Else shortCol = 1
'Set First Check Row
rw = 2
nxtChk:
'Check Column A against Column B, Row by Row
'Insert cell at non-matching data
If Cells(rw, 1) <> "" And Cells(rw, 1) < Cells(rw, 2) Then
Cells(rw, 2).Insert shift:=xlDown
Else
If Cells(rw, 2) <> "" And Cells(rw, 1) > Cells(rw, 2) Then
Cells(rw, 1).Insert shift:=xlDown
End If
End If
'If there is nothing left to check in the Short Column, we're done
If Cells(Rows.Count, shortCol).End(xlUp).Row + 1 = rw Then Exit Sub
'If not, increment Row counter and loop
rw = rw + 1
GoTo nxtChk
End Sub
[code\]
Bookmarks