Why this simple macro doesn't work?

7

71marco71

Dear friends
Someone can tell me why this simple macro doesn’t work?

Public Sub Pippo()
For j = 2 To 50
If Cells(j, 2) = "" Then
Exit For
End If
If Cells(j, 2) = "COPPIA RU*" Then
Cells(j, 4).Value = Cells(j, 4) * 2
End If
Next j
End Sub

Thank you very much for your help

I have attached a exampl

Attachment filename: pippo.xls
Download attachment: http://www.excelforum.com/attachment.php?postid=43382
 
B

Bob Phillips

Hi Marco,

How's the sun?

To do pattern matching in VBA you need to use Like, such as

Public Sub Pippo()
For j = 2 To 50
If Cells(j, 2) = "" Then
Exit For
End If
If Cells(j, 2) Like "COPPIA RU*" Then
Cells(j, 4).Value = Cells(j, 4) * 2
End If
Next j
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
T

Tom Ogilvy

Public Sub Pippo()
For j = 2 To 50
If Cells(j, 2) = "" Then
Exit For
End If
If Instr(1,Cells(j, 2),"COPPIA RU",vbTextCompare) = 1 Then
Cells(j, 4).Value = Cells(j, 4) * 2
End If
Next j
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