Combining 2 macros

APML

Board Regular
Joined
Sep 10, 2021
Messages
216
Office Version
  1. 365
Hi all, i'm not very good at macros, was hoping someone could help me turn the below 2 macros into 1.

Windows("1a.csv").Activate
Range("A4:G1048570").Select
Selection.ClearContents
Range("D3").Select
ActiveWorkbook.Save
ActiveWindow.Close

MsgBox ("File 1A Has Been CLEARED and CLOSED")

End Sub
Sub DeleteFiles()
'
' DeleteFiles Macro
'

Dim fName As String

fName = Dir("C:\CSVToday\*.*")

Do While fName <> "" & ""

If fName <> "1a.csv" Then 'or .txt or .csv or whatever

Kill "C:\CSVToday\" & fName

End If

fName = Dir

Loop

Range("A1").Select

MsgBox ("All Files Hvae Been Deleted")

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi. Try this.

VBA Code:
Sub newMacro()

'Clear and close File 1A
Windows("1a.csv").Activate
Range("A4:G1048570").Select
Selection.ClearContents
Range("D3").Select
ActiveWorkbook.Save
ActiveWindow.Close

MsgBox ("File 1A Has Been CLEARED and CLOSED")

' DeleteFiles Macro
Dim fName As String: fName = Dir("C:\CSVToday\*.*")

Do While fName <> "" & ""
    If fName <> "1a.csv" Then 'or .txt or .csv or whatever
        Kill "C:\CSVToday\" & fName
    End If

    fName = Dir
Loop

Range("A1").Select

MsgBox ("All Files Have Been Deleted")

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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