Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use For Loop to Replace Offset Cell

Tags:

excel

vba

So I wrote a For Loop code that tries to search through a particular column (Column M) of data for cells containing a description starting with "GE90" and replaces an adjecent offset cell (Column C) with "GE90 Hold".

I thought I was using the code correctly but for some reason it does not seem to work.

Dim Cell
For Each Cell In Range("M2:M" & LastRow)
    If Cell.Value = "GE90*" Then
        Cell.Offset(, -10).Value = "GE90 Hold"
    End If

Next Cell
like image 474
ksmit144 Avatar asked Feb 11 '26 21:02

ksmit144


1 Answers

Your issue is actually that you assume the asterisk in "GE90*" is a wildcard, but actually, your code is looking for the literal value "GE90*". Change your code as follows:

Dim Cell
For Each Cell In Range("M2:M" & lastrow)
    If Left(Cell.Value, 4) = "GE90" Then
        Cell.Offset(, -10).Value = "GE90 Hold"
    End If

Next Cell
like image 126
neelsg Avatar answered Feb 13 '26 14:02

neelsg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!