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
 

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.
Maybe :
VBA Code:
On Error Resume Next
With Columns("A")
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=IF(RC[12]="""",1/0,"""")"
    .SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
    .SpecialCells(xlCellTypeFormulas).ClearContents
End With
On Error GoTo 0
 
Upvote 0
Maybe :
VBA Code:
On Error Resume Next
With Columns("A")
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=IF(RC[12]="""",1/0,"""")"
    .SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
    .SpecialCells(xlCellTypeFormulas).ClearContents
End With
On Error GoTo 0
Thank you for your prompt response, I tried your code but it didn't work :(
 
Upvote 0
Cross posted Delete blank rows if column A or column M has a value

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Cross posted Delete blank rows if column A or column M has a value

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
Apologies, wasn't aware of that
 
Upvote 0
Can you please supply link(s) to all other sites where you have asked this question. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,597
Messages
6,125,738
Members
449,255
Latest member
whatdoido

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