How to save macro workbook to a new workbook as xls with same formats

Feroz90

Board Regular
Joined
Apr 25, 2019
Messages
52
Hi All,

I use the below code, will be reduced to smaller level, I am just making the rows hide, if the cell value is blank.

Also, i was trying to save the file in a path, however when we click on Alt F11, it still shows this code.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


If Target.Address = "$C$6" Then


Application.EnableEvents = False


   If Range("C6").Value = "" Then
    Rows("11:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("11:12").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C6").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$12" Then


Application.EnableEvents = False


   If Range("C12").Value = "" Then
    Rows("13:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("13:13").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C12").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$13" Then


Application.EnableEvents = False


   If Range("C13").Value = "" Then
    Rows("14:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("14:14").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C14").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$14" Then


Application.EnableEvents = False


   If Range("C14").Value = "" Then
    Rows("15:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("15:15").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C15").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$15" Then


Application.EnableEvents = False


   If Range("C15").Value = "" Then
    Rows("16:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("16:17").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C16").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$17" Then


Application.EnableEvents = False


   If Range("C17").Value = "" Then
    Rows("18:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("18:18").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C18").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$18" Then


Application.EnableEvents = False


   If Range("C18").Value = "" Then
    Rows("19:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("19:19").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C18").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$19" Then


Application.EnableEvents = False


   If Range("C19").Value = "" Then
    Rows("20:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("20:20").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C19").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$20" Then


Application.EnableEvents = False


   If Range("C20").Value = "" Then
    Rows("21:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("21:21").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C20").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$21" Then


Application.EnableEvents = False


   If Range("C21").Value = "" Then
    Rows("22:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("22:22").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C21").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$22" Then


Application.EnableEvents = False


   If Range("C22").Value = "" Then
    Rows("23:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("23:24").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C22").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$24" Then


Application.EnableEvents = False


   If Range("C24").Value = "" Then
    Rows("25:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("25:25").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C24").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$25" Then


Application.EnableEvents = False


   If Range("C25").Value = "" Then
    Rows("26:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("26:26").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C25").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$26" Then


Application.EnableEvents = False


   If Range("C26").Value = "" Then
    Rows("27:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("27:27").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C26").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$27" Then


Application.EnableEvents = False


   If Range("C27").Value = "" Then
    Rows("28:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("28:28").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C27").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$28" Then


Application.EnableEvents = False


   If Range("C28").Value = "" Then
    Rows("29:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("29:29").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C28").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$29" Then


Application.EnableEvents = False


   If Range("C29").Value = "" Then
    Rows("30:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("30:30").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C29").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$30" Then


Application.EnableEvents = False


   If Range("C30").Value = "" Then
    Rows("31:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("31:31").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C30").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$31" Then


Application.EnableEvents = False


   If Range("C31").Value = "" Then
    Rows("32:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("32:32").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C31").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$32" Then


Application.EnableEvents = False


   If Range("C32").Value = "" Then
    Rows("33:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("33:33").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C32").Select


Application.EnableEvents = True


End If


If Target.Address = "$C$33" Then


Application.EnableEvents = False


   If Range("C33").Value = "" Then
    Rows("34:63").Select
    Selection.EntireRow.Hidden = True
    Else
    Rows("34:63").Select
    Selection.EntireRow.Hidden = False
   End If


Range("C33").Select


Application.EnableEvents = True


ThisFile = Right(Range("C2").Value, 6) & " - " & Range("C5").Value & " - " & Format(Now, "mmddyyyy") & ".xls"
ActiveWorkbook.SaveAs Filename:="C:\Cash Files" & ThisFile


End If


End Sub
 
Last edited by a moderator:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this

Code:
  Dim ThisFile As String, sPath As String
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  sPath = "C:\Cash Files\"
  ThisFile = Right(Range("C2").Value, 6) & " - " & Range("C5").Value & " - " & Format(Now, "mmddyyyy")
  ActiveWorkbook.SaveCopyAs Filename:=sPath & ThisFile & ".xlsm"
  Workbooks.Open Filename:=sPath & ThisFile & ".xlsm"
  ActiveWorkbook.SaveAs Filename:=sPath & ThisFile & ".xls", FileFormat:=xlExcel8
  ActiveWorkbook.Close False
  Kill sPath & ThisFile & ".xlsm"
 
Upvote 0
Thank you, But the code in Sheet1 still remains in the Saved workbook.

Is there any option not to have a code in it.
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,236
Members
448,555
Latest member
RobertJones1986

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