Hi,
My name's Oliver and I'm currently writing my university thesis and need help with sorting out a lot of data.
Have several worksheets, where every worksheet contains between 1000-7500 columns with headers and data below. I want to delete the columns that contain certain texts (like INCI4MN, INCI5MN or INCI6MN) in the headers (row 4) because they are "empty" columns with only headers and no data below.
I've been searching for an answer but can only seem to find macros that delete all the columns in one worksheet at a time, containing only one text (like INCI4MN) in the headers. have attached the macro below.
Kind regards,
Oliver
------------------------------------------------------------------------------------------------------------------------------------------
Sub Col_Delete_by_Word()
Dim Found As Range, strWord As String, Counter As Long
strWord = Application.InputBox("Enter the word to search for.", "Delete the columns with this word", Type:=2)
If strWord = "False" Or strWord = "" Then Exit Sub 'User canceled
Set Found = Cells.Find(strWord, , , xlPart, , xlNext, False)
If Not Found Is Nothing Then
Application.ScreenUpdating = False
Do
Found.EntireColumn.Delete
Counter = Counter + 1
Set Found = Cells.Find(strWord, , , xlPart, , xlNext, False)
Loop Until Found Is Nothing
Application.ScreenUpdating = True
MsgBox Counter & " columns deleted.", vbInformation, "Process Complete"
Else
MsgBox "No match found for: " & strWord, vbInformation, "No Match"
End If
End Sub
My name's Oliver and I'm currently writing my university thesis and need help with sorting out a lot of data.
Have several worksheets, where every worksheet contains between 1000-7500 columns with headers and data below. I want to delete the columns that contain certain texts (like INCI4MN, INCI5MN or INCI6MN) in the headers (row 4) because they are "empty" columns with only headers and no data below.
I've been searching for an answer but can only seem to find macros that delete all the columns in one worksheet at a time, containing only one text (like INCI4MN) in the headers. have attached the macro below.
Kind regards,
Oliver
------------------------------------------------------------------------------------------------------------------------------------------
Sub Col_Delete_by_Word()
Dim Found As Range, strWord As String, Counter As Long
strWord = Application.InputBox("Enter the word to search for.", "Delete the columns with this word", Type:=2)
If strWord = "False" Or strWord = "" Then Exit Sub 'User canceled
Set Found = Cells.Find(strWord, , , xlPart, , xlNext, False)
If Not Found Is Nothing Then
Application.ScreenUpdating = False
Do
Found.EntireColumn.Delete
Counter = Counter + 1
Set Found = Cells.Find(strWord, , , xlPart, , xlNext, False)
Loop Until Found Is Nothing
Application.ScreenUpdating = True
MsgBox Counter & " columns deleted.", vbInformation, "Process Complete"
Else
MsgBox "No match found for: " & strWord, vbInformation, "No Match"
End If
End Sub