unknownymous
Board Regular
- Joined
- Sep 19, 2017
- Messages
- 249
- Office Version
- 2016
- Platform
- Windows
Hi Gurus,
Good day!
I found below code in deleting specific column. However, I want to apply it for all tab sheets. Suppose I have 15 sheets.
= = =
Sub DeleteSpecifcColumn()
Dim xFNum, xFFNum, xCount As Integer
Dim xStr As String
Dim xArrName As Variant
Dim MR, xRg As Range
On Error Resume Next
Set MR = Range("A1:BZ1")
xArrName = Array("old", "new", "get") 'enclose each column name with double quotes and separate them by comma
xCount = MR.Count
xStr = xArrName(xFNum)
For xFFNum = xCount To 1 Step -1
Set xRg = Cells(1, xFFNum)
For xFNum = 0 To UBound(xArrName)
xStr = xArrName(xFNum)
If xRg.Value = xStr Then xRg.EntireColumn.Delete
Next xFNum
Next
End Sub
'Source: How to delete entire columns based on header value in Excel?
= = =
For the array "new" and "get", I noticed that whenever I paste it in from my sheet to VBA there's a double quote already. Adding an extra double quote is not working like:
xArrName = Array("old", ""new"", ""get"")
Any thoughts on how to update the the VBA codes above?
Thanks in advance!
Good day!
I found below code in deleting specific column. However, I want to apply it for all tab sheets. Suppose I have 15 sheets.
= = =
Sub DeleteSpecifcColumn()
Dim xFNum, xFFNum, xCount As Integer
Dim xStr As String
Dim xArrName As Variant
Dim MR, xRg As Range
On Error Resume Next
Set MR = Range("A1:BZ1")
xArrName = Array("old", "new", "get") 'enclose each column name with double quotes and separate them by comma
xCount = MR.Count
xStr = xArrName(xFNum)
For xFFNum = xCount To 1 Step -1
Set xRg = Cells(1, xFFNum)
For xFNum = 0 To UBound(xArrName)
xStr = xArrName(xFNum)
If xRg.Value = xStr Then xRg.EntireColumn.Delete
Next xFNum
Next
End Sub
'Source: How to delete entire columns based on header value in Excel?
= = =
For the array "new" and "get", I noticed that whenever I paste it in from my sheet to VBA there's a double quote already. Adding an extra double quote is not working like:
xArrName = Array("old", ""new"", ""get"")
Any thoughts on how to update the the VBA codes above?
Thanks in advance!