C
cottage6
Sorry, this is a bit long-winded. I want to copy formulas when a new
section of data gets added. I've had some success so far, but now I'm
stuck. I have an input box that asks how many new categories are being
added, then the formulas get copied down that number of rows. I'm
having 2 problems at this point:
1. I want to group the sheets the formulas get copied to; the first 2
rows that get copied are working fine. The first row is a total row,
the second row has different formulas in it. I then need to copy just
the second row down the number of rows specified. The copy of the
second row does not go to all the sheets in the array. This is the
code:
Dim myRng As Range
Dim FoundCell As Range
Dim FirstAddress As String
Sheets(Array("Sales $", "Margin $", "Unit Sales", "Avg
Retail")).Select
Range("C65536").End(xlUp)(2).Select
With Worksheets("Sales $")
With .Range("C:C")
Set FoundCell = .Find(What:="TOTAL", _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlPrevious, _
MatchCase:=False)
End With
End With
FoundCell.Select
Selection.Resize(Selection.Rows.Count + 1, Selection.Columns.Count +
9).Select
Selection.Copy
Range("C65536").End(xlUp)(2).Select
ActiveSheet.Paste
Application.CutCopyMode = False
'**************************************************************
Sheets(Array("Sales $", "Margin $", "Unit Sales", "Avg Retail")).Select
Sheets("Sales $").Activate
Set FirstRow = Range("C65536").End(xlUp)(1)
FirstRow.Select
Dim xFirstRow As Range
Set xFirstRow = FirstRow.Resize(Selection.Rows.Count + 1,
Selection.Columns.Count + 9)
Selection.Copy
xFirstRow.Resize(LastRow).FillDown
ActiveCell.Offset(1, 0).Resize(LastRow).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
2. The Total row being copied includes a SUM formula. I need to SUM
just the range of cells being copied down. If the copied formula is
SUM(B9:B15) but if I only have 5 cells in the new range that's what I
need to sum to show. I know there's a way to use the input box value,
but I'm stuck on this also. HELP!!!
section of data gets added. I've had some success so far, but now I'm
stuck. I have an input box that asks how many new categories are being
added, then the formulas get copied down that number of rows. I'm
having 2 problems at this point:
1. I want to group the sheets the formulas get copied to; the first 2
rows that get copied are working fine. The first row is a total row,
the second row has different formulas in it. I then need to copy just
the second row down the number of rows specified. The copy of the
second row does not go to all the sheets in the array. This is the
code:
Dim myRng As Range
Dim FoundCell As Range
Dim FirstAddress As String
Sheets(Array("Sales $", "Margin $", "Unit Sales", "Avg
Retail")).Select
Range("C65536").End(xlUp)(2).Select
With Worksheets("Sales $")
With .Range("C:C")
Set FoundCell = .Find(What:="TOTAL", _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlPrevious, _
MatchCase:=False)
End With
End With
FoundCell.Select
Selection.Resize(Selection.Rows.Count + 1, Selection.Columns.Count +
9).Select
Selection.Copy
Range("C65536").End(xlUp)(2).Select
ActiveSheet.Paste
Application.CutCopyMode = False
'**************************************************************
Sheets(Array("Sales $", "Margin $", "Unit Sales", "Avg Retail")).Select
Sheets("Sales $").Activate
Set FirstRow = Range("C65536").End(xlUp)(1)
FirstRow.Select
Dim xFirstRow As Range
Set xFirstRow = FirstRow.Resize(Selection.Rows.Count + 1,
Selection.Columns.Count + 9)
Selection.Copy
xFirstRow.Resize(LastRow).FillDown
ActiveCell.Offset(1, 0).Resize(LastRow).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
2. The Total row being copied includes a SUM formula. I need to SUM
just the range of cells being copied down. If the copied formula is
SUM(B9:B15) but if I only have 5 cells in the new range that's what I
need to sum to show. I know there's a way to use the input box value,
but I'm stuck on this also. HELP!!!