Unable to writing Excel Cells

P

paolopiace

Would someone know why these few lines do not work?

Not even if I use Cells(r, 2).Value work.

Through VBA I simply must enter -1 in that cell and see it in Excel.

If Cells(r, 2) = "P" Or Cells(r, 2) = "p" Then
Cells(r, 2) = -1
End If
 
N

Norman Jones

Hi Paolo,


=============
Would someone know why these few lines do not work?

Not even if I use Cells(r, 2).Value work.

Through VBA I simply must enter -1 in that cell and see it in Excel.

If Cells(r, 2) = "P" Or Cells(r, 2) = "p" Then
Cells(r, 2) = -1
End If

=============

Try something like:

'========>>
Public Sub Tester3()
Dim r As Long

For r = 1 To 10
With Cells(r, 2)
If StrComp(.Value, "P", vbTextCompare) = 0 Then
.Value = -1
End If
End With
Next r
End Sub
'<<========
 

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