Finding a value, offsetting, changing value

saiko

New Member
Joined
Sep 8, 2002
Messages
15
I need to search a spreadsheet for the value "n", then move one row up, and insert the value "0.00".

My code below fails, as excel expects something like
If .Value = "n" Then .Value = 0

Please advise how I get it to move up one cell first, before replacing the value.


For rwIndex = 1 To 300
For colIndex = 1 To 300
With Worksheets("WHA").Cells(rwIndex, colIndex)
If .Value = "n" Then .Offset(-1, 0).Select .Value = 0
End With
Next colIndex
Next rwIndex

Thanks in advance.
David
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

saiko

New Member
Joined
Sep 8, 2002
Messages
15
I have tried this:
If Selection.Value = "n" Then Selection.Offset(-1, 0) = 0

but get a type mismatch error.
Please help.
 

bolo

Active Member
Joined
Mar 23, 2002
Messages
423
Alright mate. Try doing it this way:

Dim rwindex, colindex As Integer
For rwindex = 1 To 9
For colindex = 1 To 9
With Worksheets("Sheet1").Cells(rwindex, colindex)
If .Value = "n" Then
.Select
Selection.Offset(-1, 0).Value = 0
End If
End With
Next colindex
Next rwindex

Hope this works.
 

Forum statistics

Threads
1,143,702
Messages
5,720,375
Members
422,281
Latest member
jantoooh

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
Top