Excel macro needed for deleting column contents and column as well

talktorajpatil

New Member
Joined
May 22, 2015
Messages
6
Hi folks,

I have an excel sheet with multiple tabs and multiple columns with randon sequence on each tab.
I have two requirements -
1) I want to delete entire columns iteself from all the tabs of excel with value in 1st row as 'Select' or 'Start'
2) I would like to clear the contents (and not to delete column) with value in 1st row as 'Prompt'. (Value in 1st row should not be deleted)

I am novoice to VBA Macro for excel. Can anyone give me a complete macro for it?
Detailed help is appreciated.
Thanks in advance.

-Regards,
Raj Patil
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
something along the lines of

Dim lColumn As Long
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
ws.Activate
lColumn = Cells(1, Columns.Count).End(xlToLeft).Column

For i = lColumn To 1 Step -1

If Cells(1, i).Value = "select" Or Cells(1, i).Value = "start" Then
Cells(1, i).EntireColumn.Delete
End If
Next i

For i = lColumn To 1 Step -1
If Cells(1, i) = "prompt" Then
Cells(1, i).EntireColumn.ClearContents
Cells(1, i) = "prompt"

End If
Next i

Next ws
 
Upvote 0
Hi SteveO59L,

Thanks a lot for your help, works like boom :)
Only one thing, how can I add one more thing to it in order to make all text on all sheets in excel in black color?

-Regards,
Raj Patil
 
Upvote 0
Try
Code:
Dim lColumn As Long, ws As Worksheet
For Each ws In Worksheets
ws.Activate
ws.UsedRange.Font.ColorIndex = 1
lColumn = Cells(1, Columns.Count).End(xlToLeft).Column
For i = lColumn To 1 Step -1
If Cells(1, i).Value = "select" Or Cells(1, i).Value = "start" Then
Cells(1, i).EntireColumn.Delete
End If
Next i
For i = lColumn To 1 Step -1
If Cells(1, i) = "prompt" Then
Cells(1, i).EntireColumn.ClearContents
Cells(1, i) = "prompt"
End If
Next i
Next ws
 
Upvote 0
Thanks Michael for prompt reply :)
Sorry to bother you one more time, can we add something to delete all 'comments' added to all tabs in excel?
Also I am getting below error with your above code -

"Excel cannot complete this task with available resources. Choose less data or close other applications"
 
Last edited:
Upvote 0
Code:
Sub MM2()
Dim lColumn As Long, ws As Worksheet
For Each ws In Worksheets
ws.Activate
ws.UsedRange.Font.ColorIndex = 1
ws.Cells.ClearComments
lColumn = Cells(1, Columns.Count).End(xlToLeft).Column
For i = lColumn To 1 Step -1
If Cells(1, i).Value = "select" Or Cells(1, i).Value = "start" Then
Cells(1, i).EntireColumn.Delete
End If
Next i
For i = lColumn To 1 Step -1
If Cells(1, i) = "prompt" Then
Cells(1, i).EntireColumn.ClearContents
Cells(1, i) = "prompt"
End If
Next i
Next ws
End Sub
 
Upvote 0
Hi Folks,

After applying above macro, my excel file size is growing from 1.5 MB to ~40MB.
What can be done? Please help.

-Regards,
Raj Patil
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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