Delete blank cells if column A or column M has a value

dininaus

New Member
Joined
Jul 27, 2016
Messages
22
Hi all,

I have below macro which checks if any value exists in column A then delete the empty rows and copy-paste all the other cells with values to a new sheet and save as .csv.

Could someone please help me to amend the code so it can check if any value exists in either column A or column M (instead of just column A)

Thanks in advance

Sub OPSXLSMToCSV()

Dim myCSVFileName As String
Dim myWB As Workbook
Dim tempWB As Workbook
Dim rngToSave As Range
Dim ws As Worksheet

myDateStamp = Format(Now(), "ddmmyyyyhhmmss")

Set myWB = ThisWorkbook
myCSVFileName = "C:\Users\Desktop\Test\" & "Add_" & Environ("Username") & "_" & myDateStamp & ".csv"

On Error Resume Next

Set rngToSave = Range("A1:AE1002")
rngToSave.Copy

Set tempWB = Application.Workbooks.Add(1)
With tempWB
.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
.SaveAs FileName:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close
End With
MsgBox ("CSV File Created")
err:
Application.DisplayAlerts = True
ActiveWorkbook.Close SaveChanges:=False
Application.Quit
End Sub
 
Sorry, it is not creating the .csv after the macro is executed
The code I posted is to replace this :
VBA Code:
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,634
Messages
6,125,934
Members
449,275
Latest member
jacob_mcbride

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