Help creating new row after last row with merged cells

Fronik

New Member
Joined
May 30, 2023
Messages
7
Hello,

I have userform inserting data to sheet:

lastrow = Worksheets("1.-3.").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("1.-3.").Cells(lastrow + 1, 1).Value = TextBox2.Text
Worksheets("1.-3.").Cells(lastrow + 1, 2).Value = TextBox1.Text
Worksheets("1.-3.").Cells(lastrow + 1, 3).Value = TextBox3.Text
Worksheets("1.-3.").Cells(lastrow + 1, 13).Value = TextBox2.Text


EDIT:
And i need to automatically create new line after last row in column A with merged cells from C to J, how can i make it. Please help someone? :)
 
Last edited by a moderator:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Welcome to the Board!

You can use:
VBA Code:
Worksheets("1.-3.").Range(Cells(lastrow + 1, 3), Cells(lastrow + 1, 10)).Merge
though I would HIGHLY recommend NOT using merged cells, and use "Center Across Selection" like this, as merged cells create all sorts of headaches and should be avoided, if at all possible (see: Tom’s Tutorials For Excel: Using Center Across Selection Instead of Merging Cells – Tom Urtis)

Code for that would look like:
VBA Code:
Worksheets("1.-3.").Range(Cells(lastrow + 1, 3), Cells(lastrow + 1, 10)).HorizontalAlignment = xlCenterAcrossSelection
 
Upvote 0
@Joe4 I think that will produce an error if Worksheets("1.-3.") isn't the Activesheet,
I think it should be more like
Rich (BB code):
    With Worksheets("1.-3.")
        .Range(.Cells(lastrow + 1, 3), .Cells(lastrow + 1, 10)).Merge
    End With
 
Upvote 0
Welcome to the Board!

You can use:
VBA Code:
Worksheets("1.-3.").Range(Cells(lastrow + 1, 3), Cells(lastrow + 1, 10)).Merge
though I would HIGHLY recommend NOT using merged cells, and use "Center Across Selection" like this, as merged cells create all sorts of headaches and should be avoided, if at all possible (see: Tom’s Tutorials For Excel: Using Center Across Selection Instead of Merging Cells – Tom Urtis)

Code for that would look like:
VBA Code:
Worksheets("1.-3.").Range(Cells(lastrow + 1, 3), Cells(lastrow + 1, 10)).HorizontalAlignment = xlCenterAcrossSelection
Thank you so much! This helped a lot but still need some help, as there will be a lot of text between columns C and J, is it possible to merge it somehow if there is more text than what can fit between those rows? And How can i make it to make a new empty row automatically after?
 
Upvote 0
Thank you so much! This helped a lot but still need some help, as there will be a lot of text between columns C and J, is it possible to merge it somehow if there is more text than what can fit between those rows? And How can i make it to make a new empty row automatically after?
Oh i mean, can i use autofit somehow with that merged cell? As this merging worked for me so well but need to fit row height automatically with text and create new row after last entry :)
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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