its friday..need some help with a simple macro

cmefly

Well-known Member
Joined
May 13, 2003
Messages
683
hi,

i need a macro that does the following...

for each cell in range(c2:N2)
if cell is blank or =0 then put an "X"

can anyone help with this???

thanks,

Marc
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try

Code:
Dim rng As Range
Set rng = Sheets("sheet1").Range("C2:N2")

For Each Item In rng
    If Item.Value = "" Then
        Item.Value = "X"
        Else
        If Item.Value = 0 Then
            Item.Value = "X"
        End If
    End If
Next Item
 
Upvote 0
Code:
Sub Fanugi()
Dim cl As Range
For Each cl In Range("$C$2:$N$2")
If Len(cl) = 0 Or cl = 0 Then cl = "X"
Next cl
End Sub

lenze
 
Upvote 0
kgkev,

thanks for your quick response...i have one other request and given that you are great at this, you shouldn't even have to flex your brain lol

your macro worked....i just need the range to be Ci to Ni (where i is a variable)

i basically need it to search each row in the given range...and ideas?
 
Upvote 0
not sure how you want to select which row - but this opens an input box

Code:
Sub test()
Dim rng As Range

i = InputBox("What Row?")

Set rng = Sheets("sheet1").Range("C" & i & ":" & "N" & i)

For Each Item In rng
    If Item.Value = "" Then
        Item.Value = "X"
        Else
        If Item.Value = 0 Then
            Item.Value = "X"
        End If
    End If
Next Item
End Sub
 
Upvote 0
might be better - Just highlight anywhere on the row and run the macro


Code:
Sub test()
Dim rng As Range

'i = InputBox("What Row?")
i = ActiveCell.Row

Set rng = Sheets("sheet1").Range("C" & i & ":" & "N" & i)

For Each Item In rng
    If Item.Value = "" Then
        Item.Value = "X"
        Else
        If Item.Value = 0 Then
            Item.Value = "X"
        End If
    End If
Next Item
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,456
Messages
6,055,544
Members
444,795
Latest member
cjohnson333

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