some help?

travis.m.roberts

Board Regular
Joined
Jul 7, 2009
Messages
62
I found this code and can't seem to get it to work for me. When a new sheet is inserted this code inserts/copies a row of formulas and stuff and then inserts a new row with the same formulas but with the new sheet name's applied. What I can't figure out is how to control what rows it starts at or ends at. I have a spreadsheet that, every month we have to add a new tab too and update the summary tab. This macro will be miracle if I can get it to work. The problem is that my spreadsheet is set on the first column and I have totals at the bottom. Is there a way to get this macro to insert rows NOT as the last row?

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim NewRowCell As Range

Set NewRowCell = Sheets("Main Sheet").Range("a65536").End(xlUp).Offset(1, 0)
NewRowCell.Offset(-1, 0).EntireRow.Copy Destination:=NewRowCell
NewRowCell.EntireRow.Replace What:=NewRowCell.Offset(-1, 0).Value, Replacement:=Sh.Name, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
NewRowCell.FormulaR1C1 = "=MID(CELL(""filename""," & Sh.Name & _
"!RC), FIND(""]"",CELL(""filename""," & Sh.Name & "!RC))+1,31)"
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

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