I am using VBA code to delete columns in an excel sheet that are not required. Part of the code references a sheet name. Can I insert additional code so that the worksheet name (referenced here as Sheet1) is pulled from an input or referene cell in the workbook? I need to change the worksheet each month to the name of the month but don't want to have to change the VBA code each month.
Sub DeleteColumns()
Dim delColumn As Range, cell As Range
Set delColumn = Worksheets("Delete").Range("A1:A59")
For Each cell In delColumn.Cells
If Len(cell.Value) > 0 Then
Set ColumnName = Worksheets("Sheet1").Rows(1).Find(cell.Value, , xlValues, xlWhole)
If Not ColumnName Is Nothing Then ColumnName.EntireColumn.Delete
End If
Set ColumnName = Nothing
Next cellUpload Image
End Sub
Sub DeleteColumns()
Dim delColumn As Range, cell As Range
Set delColumn = Worksheets("Delete").Range("A1:A59")
For Each cell In delColumn.Cells
If Len(cell.Value) > 0 Then
Set ColumnName = Worksheets("Sheet1").Rows(1).Find(cell.Value, , xlValues, xlWhole)
If Not ColumnName Is Nothing Then ColumnName.EntireColumn.Delete
End If
Set ColumnName = Nothing
Next cellUpload Image
End Sub