How to update a range of cells if cell value is equal to...

J

Jen_T

I am having trouble with a piece of code in excel 2007 where I would like to
check a cell value in column "W" which is column 23, if equal to "Y" than
update from columns "X:BV" row 2 to last row the value to "N", if not do
nothing.

I have attached the code I am currently using:

Dim rowCounter As Double
Dim bottomRow As Double


For rowCounter = 2 To bottomRow
If Sheet7.Cells(rowCounter, 23).Value = "Y" Then
Sheet7.Range("X" + Trim(Str(rowCounter)) + ":BV" + _
Trim(Str(rowCounter))).Value = "N"
End If
Next rowCounter
Any suggestions would be greatly appreciated. Thank you
 
J

Jacob Skaria

Hi Jen

Try the below and feedback

Dim rowCounter As Double
Dim bottomRow As Double

For rowCounter = 2 To bottomRow
If UCase(Sheets("Sheet3").Range("W" & rowCounter)) = "Y" Then
Sheets("Sheet3").Range("X" & rowCounter & ":BV" & rowCounter) = "N"
End If
Next


If this post helps click Yes
 
M

Mike H

Jen,
I am having trouble with a piece of code in excel 2007

What trouble? I ran this code and if it finds a Y in col 23 then the row as
far as column BV gets's populated with N. What happens for you?

Mike

:

where I would like to
 
M

Mike H

I should have added I prefer this line to yours

Sheet7.Range(("X" & rowCounter & ":BV" & rowCounter)).Value = "N"

Mike
 
J

Jen_T

My macro will not replace the values of all rows from columns"x" to "bv" if
"w" ="y", I need to have the macro does this from row 2 to last row.
 
M

Mike H

Jacob has shown you the solution to that use

UCASE

If ucase(Sheet7.Cells(rowCounter, 23).Value) = "Y"

Mike
 
J

Jen_T

Hi Jacob,
The code is not working, it will not update rows 2 to last for columns X
through BV if W ="Y". Not sure what is wrong... I copied your code into a
module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top