VBA Loop Speed - String Search and update

JJCA99

Board Regular
Joined
Dec 4, 2014
Messages
50
Hello all,

I need some help to improve my code. Right now I only have about 1700 lines to go through and the loop i created takes 5-10min. I must be doing something wrong or is there a way to speed up this code?

Code searches one column per cell for specific word (2 options) then updates second column based on string.

Code:
'HW V SW


Sheets("Keep").Select
Dim sCellVal As String
HS = Cells(Rows.Count, 2).End(xlUp).Row
For c = 6 To HS
sCellVal = Cells(c, 18).Value


If InStr(sCellVal, "*SOFTWARE*") > 0 Or _
 InStr(sCellVal, "*SW*") > 0 Then
Cells(c, 23) = "SOFTWARE"
Else: Cells(c, 23) = "HARDWARE"
End If


Next c

Appreciate any input.

Thanks,
Justin
 
Maybe this would be better.
Code:
Sub Maybe_With_Formula()
    With Range("Y2:Y" & Cells(Rows.Count, 18).End(xlUp).Row)
        .Formula = "=IF(COUNT(SEARCH({""SOFTWARE"", "" SOFTWARE"", "" SOFTWARE "",""SW "","" SW "","" SW""},RC[-7])),""Software"",""Hardware"")"
        .Value = .Value
    End With
End Sub

However, if Norie's code fits the bill, you should stick with that as it is the fastest and that is what you're after.
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,828
Messages
6,181,213
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top