EXCEL Help VBA - Insert Empty Cell Function

I need help with excel VBA function.

I have data that looks like

    ColA     ColB
    a123     a123
    a124     a124
    a127     a126
    a128     a127
    ....     ....

I want to compare the contents of ColA and ColB where the contents are different. I want to insert an empty cell in column A. Thus, the result will look like this:

ColA     ColB
a123     a123
a124     a124
         a126
a127     a127
....     ....

Any suggestions on how I can do this in Excel.

Thanks in advance


UPDATED


I tried the method below with the following code to insert a cell and it works fine, now I understand when I run it, but I need some more functionality.

first_col.Cells(row, 1).Select
Selection.Insert Shift:=xlDown

ColA "a" ColB "a", ColA, ColC ( ). ColB , ColB. , , If, , IF.

Set other_col = Range("C1:C100")

//if substring of ColA > substring of ColB
   first_col.Cells(row, 1).Select
   Selection.Insert Shift:=xlDown
   other_col.Cells(row, 1).Select
   Selection.Insert Shift:=xlDown
//else 
   second_col.Cells(row, 1).Select
   Selection.Insert Shift:=xlDown
+3
3

:

Sub Expand()

    Dim first_col As Range, cell As Range
    Dim row As Integer

    Set first_col = Range("A2:A100")

    For Each cell In first_col
        If Right(cell.Value, 3) < Right(cell.Offset(0, 1).Value, 3) Then
            ' Shift in here
        End If
    Next cell

End Sub

"" , .

: , , .select:

first_col.Cells(row, 1).Select
Selection.Insert Shift:=xlDown

:

first_col.cells(row, 1).insert shift:=xlDown

"" "" VBA.

+3

VBA, , , . ( ):

Sub Expand()
    Dim first_col as Range
    Dim second_col as Range
    Dim row as Integer

    Set first_col = Range("A2:A100")
    Set second_col = Range("B2:B100")

    For row = 1 To second_col.Rows.Count
        If first_col.Cells(Row, 1).Value <> second_col.Cells(Row, 1).Value Then
            '// code to insert the row'
        End If
    Next row
End Sub
+1

i record a macro, select some cells and insert and i tried to create my own sub and its work

Range("c16:e16").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

change note this code merges with merged cells

0
source

Source: https://habr.com/ru/post/1748514/


All Articles