Insert cell if...

Closed
most - Jan 11, 2010 at 04:14 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jan 11, 2010 at 09:36 PM
Hello,

I have problem in excell
Assume i have data :
A1=1 B1=1 C1=xxxx
A2=2 B2=2 C2=xxxx
A3=3 B3=4 C3=xxxx
A4=4 B4=5 C4=xxxx
A5=5
how can i make data in column B&C automatically do insert cell, when two column (A and B) didn't match. ex. there is a new cell insert after B2&C2. please help me write macro for this.
thank you

1 response

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Jan 11, 2010 at 09:36 PM
not clear to me. do you mean that there are data in coumns A,B,C,D,E like that and that if in a particular row A and B do not macthc in sert a cell betyween existing B and C.

suppose your data is iike this

1 1 a q
2 2 s w
3 4 d e
4 5 f r

now after running the macro given below the data will be like this

1 1 a q
2 2 s w
3 4 d e
4 5 f r
IS THIS DO YOU WANT . That is the data will be shifted to the right

If this is so try this macro (if this is not what you want give someclear examples

Sub test()
Dim r As Range, c As Range
Set r = Range(Range("A1"), Range("A1").End(xlDown))
For Each c In r
If c <> c.Offset(0, 1) Then
c.Offset(0, 2).Insert shift:=xlShiftToRight
End If
Next c
End Sub
0