amandajean
04-13-2020, 11:57 AM
Hola,
I am putting together a database. I have two separate macros I need to run and they work great individually. Right now I am running the macros individually on each spreadsheet. I have hundreds of workbooks full of data to go through..trying to speed up the process. Can someone help me edit the code? I think I need to do an array, but I'm too new to figure that out.
Macro 1 (gain) needs to run on the following spreadsheet names: Lat vHIT Gains, LARP vHIT Gains, RALP Gains
Sub deleteIrrelevantColumnsgain()
Dim currentColumn As Integer
Dim columnHeading As String
For currentColumn = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
'CHECK WHETHER TO KEEP THE COLUMN
Select Case columnHeading
Case "Gain"
'Do nothing
Case Else
ActiveSheet.Columns(currentColumn).Delete
End Select
Next
End Sub
Macro 2 (eye head) needs to run on the following spreadsheet names: Lat vHIT VOR Traces, LARP vHIT Traces, RALP vHIT Traces
Sub deleteIrrelevantColumnseyehead()
Dim currentColumn As Integer
Dim columnHeading As String
For currentColumn = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
'CHECK WHETHER TO KEEP THE COLUMN
Select Case columnHeading
Case "Eye", "Head"
'Do nothing
Case Else
ActiveSheet.Columns(currentColumn).Delete
End Select
Next
End Sub
I am putting together a database. I have two separate macros I need to run and they work great individually. Right now I am running the macros individually on each spreadsheet. I have hundreds of workbooks full of data to go through..trying to speed up the process. Can someone help me edit the code? I think I need to do an array, but I'm too new to figure that out.
Macro 1 (gain) needs to run on the following spreadsheet names: Lat vHIT Gains, LARP vHIT Gains, RALP Gains
Sub deleteIrrelevantColumnsgain()
Dim currentColumn As Integer
Dim columnHeading As String
For currentColumn = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
'CHECK WHETHER TO KEEP THE COLUMN
Select Case columnHeading
Case "Gain"
'Do nothing
Case Else
ActiveSheet.Columns(currentColumn).Delete
End Select
Next
End Sub
Macro 2 (eye head) needs to run on the following spreadsheet names: Lat vHIT VOR Traces, LARP vHIT Traces, RALP vHIT Traces
Sub deleteIrrelevantColumnseyehead()
Dim currentColumn As Integer
Dim columnHeading As String
For currentColumn = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
'CHECK WHETHER TO KEEP THE COLUMN
Select Case columnHeading
Case "Eye", "Head"
'Do nothing
Case Else
ActiveSheet.Columns(currentColumn).Delete
End Select
Next
End Sub