Help with insert row and merge cells code

Fedor

New Member
Joined
Feb 1, 2016
Messages
5
Hello mrexcel Community :)

I have a problem with my VBA Code in Excel, I dont speak VBA or even english :laugh:

The code I have tried to create is not doing what I want it to do. When I click on the Command Button than it does not create a new Row.
The result of my tryings is this one:

Code:
Private Sub CommandButton4_Click()
    Dim finden, cell As Range
    Dim Wert As String
    Dim MyRange As Object
    Set finden = Range("B1:B500")
    
    For Each cell In finden
        If cell.Text = "Names:" Then
            cell.Select
            With ActiveCell
                .Offset(1, 0).Activate
            End With
        Else
        End If
    Next
    ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
    Range(Cells(ActiveCell.Row, "B"), Cells(ActiveCell.Row, "F")).MergeCells = True
End Sub

I have 3 lists in my excel sheet and my idea was, when I click on an button, it will add a new row underneath and merge the cells from B-F.

I apologize for my bad english and hope someone can help me.

screeen.png
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hello mrexcel Community :)

I have a problem with my VBA Code in Excel, I dont speak VBA or even english :laugh:

The code I have tried to create is not doing what I want it to do. When I click on the Command Button than it does not create a new Row.
The result of my tryings is this one:

Code:
Private Sub CommandButton4_Click()
    Dim finden, cell As Range
    Dim Wert As String
    Dim MyRange As Object
    Set finden = Range("B1:B500")
    
    For Each cell In finden
        If cell.Text = "Names:" Then
            cell.Select
            With ActiveCell
                .Offset(1, 0).Activate
            End With
        Else
        End If
    Next
    ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
    Range(Cells(ActiveCell.Row, "B"), Cells(ActiveCell.Row, "F")).MergeCells = True
End Sub

I have 3 lists in my excel sheet and my idea was, when I click on an button, it will add a new row underneath and merge the cells from B-F.

I apologize for my bad english and hope someone can help me.

screeen.png
Hi Fedor, welcome to the boards.

If I am understanding your code correctly, try out the following tweaked version in a COPY of your workbook:

Code:
Private Sub CommandButton4_Click()
    Dim finden, cell As Range
    Dim Wert As String
    Dim MyRange As Object
    Set finden = Range("B1:B500")
    
    For Each cell In finden
        If cell.Text = "Names:" Then
            cell.Offset(1, 0).Activate
            With ActiveCell
                .EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
            End With
                    Range(Cells(ActiveCell.Row, "B"), Cells(ActiveCell.Row, "F")).MergeCells = True
                
        End If
    Next
End Sub
 
Upvote 0
yay this works! thank you very much!
but there is one issue, when you click on the Command button and a new row was inserted than you need to deselect it to make the button work again.
 
Upvote 0
yay this works! thank you very much!
but there is one issue, when you click on the Command button and a new row was inserted than you need to deselect it to make the button work again.
Deselect the row or the button?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top