comparing strings

O

oercim

Hello, I have a problem. I want to compare string in vba however I couldn't manage.My statemets are like below:


If Sheets("Sayfa1").Cells(1, 1) ="TRUE" Then
Sheets("Sayfa1").Cells(1, 2) = 1
End If


These statements doesnt give error but it doesnt also print "1" cell(1,2) even the cell(1,1)="TRUE.

How can I do this? Thanks a lot.
 
C

Claus Busch

Hi,

Am Mon, 27 Aug 2012 05:49:55 -0700 (PDT) schrieb oercim:
If Sheets("Sayfa1").Cells(1, 1) ="TRUE" Then
Sheets("Sayfa1").Cells(1, 2) = 1
End If

try:
With Sheets("Sayfa1")
.Cells(1, 2) = -(Cells(1, 1) = True)
End With


Regards
Claus Busch
 
O

oercim

Thanks a lot for the answer. Hut I couldn't understnad the statements. For example

If Sheets("Sayfa1").Cells(1, 1) ="JOHN" Then
Sheets("Sayfa1").Cells(1, 2) = $500
End If

How will I do this "with- end with" statements. Thank a lot.
 
C

Claus Busch

Hi,

Am Mon, 27 Aug 2012 06:40:31 -0700 (PDT) schrieb oercim:
If Sheets("Sayfa1").Cells(1, 1) ="JOHN" Then
Sheets("Sayfa1").Cells(1, 2) = $500
End If

How will I do this "with- end with" statements. Thank a lot.

try:
With Sheets("Sayfa1")
If .Cells(1, 1) = "JOHN" Then
.Cells(1, 2) = 500
End If
End With


Regards
Claus Busch
 
R

Riyas Majeed

Hello, I have a problem. I want to compare string in vba however I couldn't manage.My statemets are like below: If Sheets("Sayfa1").Cells(1, 1) ="TRUE" Then Sheets("Sayfa1").Cells(1, 2) = 1 End If These statements doesnt give error but it doesnt also print "1" cell(1,2) even the cell(1,1)="TRUE. How can I do this? Thanks a lot.

Hi,

from TRUE is a keyword. So if you want to use TRUE as keyword as such, in the sheet u have to write 'TRUE (prefix a ' )

but if you are using TRUE as a Boolean keyword itself, then modify the codeas below

If Sheets("Sayfa1").Cells(1, 1) = True Then
Sheets("Sayfa1").Cells(1, 2) = 1
End If


(Remove the " " for TRUE)
 
R

Riyas Majeed

Hello, I have a problem. I want to compare string in vba however I couldn't manage.My statemets are like below: If Sheets("Sayfa1").Cells(1, 1) ="TRUE" Then Sheets("Sayfa1").Cells(1, 2) = 1 End If These statements doesnt give error but it doesnt also print "1" cell(1,2) even the cell(1,1)="TRUE. How can I do this? Thanks a lot.

Hi,

TRUE is a reserved keyword. If you want to use TRUE simply as a string, then in the sheet u have to write 'TRUE (prefix a ' )

but if you are using TRUE as a Boolean keyword itself, then modify the codeas below

If Sheets("Sayfa1").Cells(1, 1) = True Then
Sheets("Sayfa1").Cells(1, 2) = 1
End If


(Remove the " " for TRUE)
 

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