Macro Question

  • Thread starter Thread starter Rodney
  • Start date Start date
R

Rodney

Hi guys,

I have got the following code which looks for a specific value in column A
(1), then i want it to change the value in column G (7) to another value. For
some reason this doesn't seem to be happening with the following code. Any
thoughts?

For i = 1 To Rows.Count
If Cells(i, 1).Value = "Value1" Then
Cells(i, 7).Value = "Value 2"
End If

Cheers,
Rod
 
Sub sdf()
For i = 1 To Rows.Count
If Cells(i, 1).Value = "Value1" Then
Cells(i, 7).Value = "Value 2"
End If
Next
End Sub


works for me

But this works for an exact text match. the values in column A must be:

Value1

with no leading or trailing spaces.
 
You were missing a "Next" to go with your "For". Also, the following fixes
when you select a group of rows and the first row is not row 1.

For i = 1 To Selection.Rows.Count
MsgBox Selection.Rows(i).Row
If Cells(i, 1).Value = "Value1" Then
Cells(i, 7).Value = "Value 2"
End If
Next

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 
Back
Top