MODIFY MACRO to value out columns with specified headers!

fisht

New Member
Joined
Sep 1, 2013
Messages
47
Hi All-

I have a macro that I currently use to save and value out a worksheet to a new workbook. I need some help in adjusting the macro to only value out columns with specific headers in row 24. For example: if the row headers say either "cost", "revenue", and "profit" (no matter what column), I would like to the macro to only value out those columns when saving the worksheet out to a new workbook.

Please help!!

Below is the current code:

Sub savePSh()
Dim sh As Worksheet
ActiveWorkbook.Sheets("P&L").Copy
Set sh = ActiveWorkbook.Sheets(1)
sh.Name = sh.Range("E6") & "_" & Format(Date, "yyyy mm dd")
With sh.UsedRange.Cells
.Value = .Value
End With
ActiveWorkbook.SaveAs "c:\" & sh.Range("E6") & "_" & Format(Date, "yyyy mm dd")
ActiveWorkbook.Close False
End Sub
 
This tested out ok on the valuing part, so it should be OK. Let me know how it goes.
Code:
Sub fisht()
'for Sub savePSh()
Dim sh As Worksheet
Dim LR As Long
Dim LC As Long
LR = Cells(Rows.Count, "A").End(xlUp).Row + 1
LC = ActiveSheet.UsedRange.Columns.Count
ActiveWorkbook.Sheets("P&L").Copy
Set sh = ActiveWorkbook.Sheets(1)
sh.name = sh.Range("E6") & "_" & Format(Date, "yyyy mm dd")
For I = 1 To LC
    If Cells(24, I).Value = "Cost" Or Cells(24, I).Value = "Revenue" Or Cells(24, I).Value = "Profit" Then
        Else:   With Cells(24, I).Resize(LR - 24)
                    .Value = .Value
                End With
    End If
Next I
ActiveWorkbook.SaveAs "c:\" & sh.Range("E6") & "_" & Format(Date, "yyyy mm dd")
ActiveWorkbook.Close False
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,850
Messages
6,193,355
Members
453,790
Latest member
yassinosnoo1

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