VBA Paste Formulas Across Worksheets to Last Row of Data


New Member
Mar 19, 2013

I have a macro that splits my data by column x and pastes it into new worksheets for each unique item in column X. However, while the formatting is preserved I lose all the formulae. Is there a way of preserving the formulae while I do this? Or would I need to create a separate macro to copy the formulas from the original worksheet across all the new tabs created? The problem I have is that each worksheet has a different amount of rows so if it's a separate macro then it would need to use LastRow.

Here is the macro I have:
Sub LALD()
Set asheet = ActiveSheet
LastRow = asheet.Range("X" & Rows.Count).End(xlUp).Row
myarray = uniqueValues(asheet.Range("X20:X" & LastRow))
For i = LBound(myarray) To UBound(myarray)
Sheets.Add.Name = myarray(i)
asheet.Range("A19:CN" & LastRow).AutoFilter Field:=24, Criteria1:=myarray(i)
asheet.Range("A1:CN" & LastRow).SpecialCells(xlCellTypeVisible).Copy _
asheet.Range("A19:CN" & LastRow).AutoFilter
Next i
End Sub
Private Function uniqueValues(InputRange As Range)
Dim cell As Range
Dim tempList As Variant: tempList = ""
For Each cell In InputRange
If cell.Value <> "" Then
If InStr(1, tempList, cell.Value) = 0 Then
If tempList = "" Then tempList = Trim(CStr(cell.Value)) Else tempList = tempList & "|" & Trim(CStr(cell.Value))
End If
End If
Next cell
uniqueValues = Split(tempList, "|")
End Function

I am using Excel 2010.
Thank you in advance for your help. Much appreciated.



New Member
Mar 19, 2013
Further to my previous post, I have written a macro to copy the first row of data on the original sheet to the first row of data on the other sheets. Please can you advise how I amend this so that it copies the formulas down to the last row?
Sub CopyFormula()
ActiveCell.Offset(-3, 0).Rows("1:1").EntireRow.Select
Sheets("Mr X").Select
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets(Array("Mr X", "Mr Y")).Select Replace:=False
ActiveCell.Offset(2, 0).Rows("1:1").EntireRow.Select
ActiveCell.Offset(2, -85).Range("A1").Activate
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Sub

Thanks so much.


Forum statistics

Latest member

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...