Forum Discussion

AJanaway's avatar
AJanaway
Copper Contributor
Aug 13, 2024

My Macro is copying formula's instead of pasting values

Hi All,   I have an excel spreadsheet that I generate using data that pulls from a few different tabs within the spreadsheet. I am trying to run a macro that copies everything in each tab as value...
  • HansVogelaar's avatar
    HansVogelaar
    Aug 15, 2024

    AJanaway 

    That does not appear to be the full macro - it would fail since you don't assign a value to the variable fil. anyway, the code could look like this:

    Sub SaveThisReport()
        Dim fil As String
        Dim Ws As Worksheet
        Dim LMonth As Integer
        Dim LValue As String
    
        'Get current month number
        LMonth = Month(Date)
        LYear = Year(Date)
        LValue = Format(LMonth, "00")
        tmpYear = LYear
    
        Application.DisplayAlerts = False
    
        'Save report
        ActiveWorkbook.SaveAs fil
    
        For Each Ws In Worksheets
            With Ws.UsedRange
                .Value = .Value
            End With
        Next Ws
    
        Sheets("Control_Sheet").Delete
    
        Sheets("Sheet 1").Select
        Range("A1").Select
    
        ActiveWorkbook.SaveAs fil
    
        Application.DisplayAlerts = True
        MsgBox "Process Complete", vbOKOnly, "Procedure Update"
    End Sub

Resources