I have some code that I want to search thru a row of column names (row 7) and identify whether or not the column name is part of a list I have. If it detects that it is part of the list, then it will go down that column and convert the formulas to values by doing Sheet.Range.Value=Sheet.Range.Value
.
For example, if it detects the word Apple or Banana, it will loop thru the column and convert the formulas into values.
However, I have found that this probably isn't the most efficient way to achieve this. I have the code listed below. Does anyone know how to make this more efficient?
Dim lastcol, lastrow As Long
lastcol = Sheets("Sheet1").Cells(7, Columns.Count).End(xlToLeft).Column
lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Dim z
For i = 5 To lastcol
If Sheets("Sheet1").Cells(7, i).value = "Banana" Then
For z = 9 To lastrow
Sheets("Sheet1").Cells(z, i).value = Sheets("Sheet1").Cells(z, i).value
Next z
End If
If Sheets("Sheet1").Cells(7, i).value = "Apple" Then
For z = 9 To lastrow
Sheets("Sheet1").Cells(z, i).value = Sheets("Sheet1").Cells(z, i).value
Next z
End If
If Sheets("Sheet1").Cells(7, i).value = "Coconut" Then
For z = 9 To lastrow
Sheets("Sheet1").Cells(z, i).value = Sheets("Sheet1").Cells(z, i).value
Next z
End If
If Sheets("Sheet1").Cells(7, i).value = "Kiwi" Then
For z = 9 To lastrow
Sheets("Sheet1").Cells(z, i).value = Sheets("Sheet1").Cells(z, i).value
Next z
End If
If Sheets("Sheet1").Cells(7, i).value = "Watermelon" Then
For z = 9 To lastrow
Sheets("Sheet1").Cells(z, i).value = Sheets("Sheet1").Cells(z, i).value
Next z
End If
If Sheets("Sheet1").Cells(7, i).value = "Orange" Then
For z = 9 To lastrow
Sheets("Sheet1").Cells(z, i).value = Sheets("Sheet1").Cells(z, i).value
Next z
End If
Next i