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.

 

Fishboy

Well-known Member
Joined
Feb 13, 2015
Messages
4,261
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.

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
 

Fedor

New Member
Joined
Feb 1, 2016
Messages
5
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.
 

Fishboy

Well-known Member
Joined
Feb 13, 2015
Messages
4,261
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?
 

Fedor

New Member
Joined
Feb 1, 2016
Messages
5
Deselect the row or the button?
Ah okay i see, when you click to fast than it selects the button and i need to deselect it... Thank you very much for your help Fishboy, you are awesome!
 

Fishboy

Well-known Member
Joined
Feb 13, 2015
Messages
4,261
Ah okay i see, when you click to fast than it selects the button and i need to deselect it... Thank you very much for your help Fishboy, you are awesome!
Happy to help mate
 

Forum statistics

Threads
1,082,297
Messages
5,364,373
Members
400,793
Latest member
hamzayagiz

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top