Insert New Row including the formating

xluser26

New Member
Joined
Dec 28, 2010
Messages
18
Hope Everyone is well,

I'm trying to do something very simple - I am using the code below to add a new row on the top row by clicking a Command Button. I'm having a hard time also including the format, some cells on the row have to be a specific format (Text, Date, Currency, Center aligned, etc.) Note: I'm using an auto expand table.

This is the code i am using:

Private Sub CommandButton1_Click()
Dim mySheets
Dim i As Long

mySheets = Array("Sheet1")

For i = LBound(mySheets) To UBound(mySheets)
With Sheets(mySheets(i))
.Range("B8").EntireRow.Insert shift:=x1Down
.Range("B8:D8").Borders.Weight = xlThin
End With
Next i
End Sub

----------------------

I got this code from a search to add a new row online, so I am trying to build off of it.

Thank you for all the help.

xluser26 :)
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Maybe this
Code:
Private Sub CommandButton1_Click()
With Rows("8")
    .Copy
    .Insert
    .ClearContents
End With
End Sub
 
Upvote 0
Appreciate it Michael.

I have a table ("my auto expand table), which in order for the above code to work, i have to convert it back to a range table, which then doesn't allow a vlookup formula to work anymore because it doesn't copy it to the new row.

The VLOOKUP formula is =VLOOKUP($B4,UNITBRSIZE_TABLE,2,FALSE)
its in the column over.

Again thank you,

xluser26:)
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,348
Members
452,638
Latest member
Oluwabukunmi

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