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 :LOL:

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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hello mrexcel Community :)

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

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,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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