comparing strings

Discussion in 'Microsoft Excel Programming' started by oercim, Aug 27, 2012.

  1. oercim

    oercim Guest

    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.
     
    oercim, Aug 27, 2012
    #1
    1. Advertisements

  2. oercim

    Claus Busch Guest

    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
    --
    Win XP PRof SP2 / Vista Ultimate SP2
    Office 2003 SP2 /2007 Ultimate SP2
     
    Claus Busch, Aug 27, 2012
    #2
    1. Advertisements

  3. oercim

    oercim Guest

    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.
     
    oercim, Aug 27, 2012
    #3
  4. oercim

    Claus Busch Guest

    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
    --
    Win XP PRof SP2 / Vista Ultimate SP2
    Office 2003 SP2 /2007 Ultimate SP2
     
    Claus Busch, Aug 27, 2012
    #4
  5. oercim

    oercim Guest

    27 Ağustos 2012 Pazartesi 16:50:05 UTC+3 tarihinde Claus Busch yazdı:
    > 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
    >
    > --
    >
    > Win XP PRof SP2 / Vista Ultimate SP2
    >
    > Office 2003 SP2 /2007 Ultimate SP2
     
    oercim, Aug 27, 2012
    #5
  6. oercim

    Riyas Majeed Guest

    On Monday, August 27, 2012 6:19:55 PM UTC+5:30, oercim wrote:
    > 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)
     
    Riyas Majeed, Aug 27, 2012
    #6
  7. oercim

    Riyas Majeed Guest

    On Monday, August 27, 2012 6:19:55 PM UTC+5:30, oercim wrote:
    > 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)
     
    Riyas Majeed, Aug 27, 2012
    #7
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Brandon

    Excel Macro Strings

    Brandon, Jul 10, 2003, in forum: Microsoft Excel Programming
    Replies:
    16
    Views:
    27,612
    Tom Ogilvy
    Jul 14, 2003
  2. Rod

    Finding strings within strings

    Rod, Dec 2, 2003, in forum: Microsoft Excel Programming
    Replies:
    1
    Views:
    495
    Chip Pearson
    Dec 2, 2003
  3. Guest

    Finding strings within strings

    Guest, Dec 2, 2003, in forum: Microsoft Excel Programming
    Replies:
    1
    Views:
    434
    J.E. McGimpsey
    Dec 2, 2003
  4. Odin

    Comparing character strings in separate cells

    Odin, Oct 11, 2006, in forum: Microsoft Excel Programming
    Replies:
    6
    Views:
    278
    NickHK
    Oct 13, 2006
  5. Guest

    Comparing Formula Strings after Row has been Inserted

    Guest, May 7, 2007, in forum: Microsoft Excel Programming
    Replies:
    3
    Views:
    301
    Susan
    May 7, 2007
  6. Guest

    comparing strings on seperate worksheets

    Guest, Jul 6, 2007, in forum: Microsoft Excel Programming
    Replies:
    5
    Views:
    205
    Dan R.
    Jul 6, 2007
  7. CG Rosén

    comparing text strings

    CG Rosén, Sep 24, 2007, in forum: Microsoft Excel Programming
    Replies:
    2
    Views:
    217
    Bob Phillips
    Sep 24, 2007
  8. AlanR

    Comparing Similarity of Strings and Returning Best Match

    AlanR, Dec 14, 2010, in forum: Microsoft Excel Programming
    Replies:
    6
    Views:
    2,204
    Pete_UK
    Dec 16, 2010
Loading...