+ Reply to Thread
Results 1 to 3 of 3

If statement frustration

  1. #1
    Registered User
    Join Date
    12-01-2006
    Location
    Alabama, USA
    MS-Off Ver
    MS Office 10
    Posts
    28

    If statement frustration

    Hi,

    First I want to thank T-J for getting me this far. I thought I'd post to a new thread because the subject has changed.

    I'm not used to VBE syntax. In all other languages I know, you can have multiple executable statements within your If..then..else construct. From what I've read and seen in VBE that's not true. For example: If var = 1 then [statement 1], [statement 2], else [statement 3] end if. VBE only lets you do, If var = 1 then [statement 1] else [statement 2] end if. I need help in getting around this.

    My code is looping through rows, checking each cell. The cell data is split into an array. I'm looping through the array looking for "@". When found, I'm moving over one row and pasting until no more data.

    My problem is in the If statement where I have some of it commented out for an example. If VBE would execute everything between If and Else it would work as wanted, but since I can't, it's picking up and moving data that doesn't have the "@". I don't know how to fix this. Also, how do you do a Null or No action or drop through in an If Statement?

    Please Login or Register  to view this content.
    BTW, if there is a better way to do what I'm doing or an enhancement, please let me know.

    JDB

  2. #2
    Registered User
    Join Date
    12-01-2006
    Location
    Alabama, USA
    MS-Off Ver
    MS Office 10
    Posts
    28

    Never mind on blocks of executable code

    I don't know how I fixed it, the code wouldn't even complie, but I now have the If statement working right. I still don't know about a null or no action statment or placeholder.

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    jdbegg

    VBA does let you have many if's

    If Var = 1 then
    do something1
    elseif Var = 2
    Do Something2
    elseif Var = 35
    Do Something3
    Elseif Var > 50 and Var < 60 then
    do something5
    else
    Do Something6
    End If

    You can also use
    Select Case Var
    case 1
    do something1
    Case 2
    do something2
    Case 35
    do something3
    case else
    do something4
    End Select


    In your code you can replace these 3 lines of code
    rowNum = strRow & intRow 'Move pointer to next row
    Worksheets(1).Range(rowNum).Activate ' Activate cell so split will process it
    Cell_array = Split(ActiveCell.Value, Chr(10))

    with this 1 line & do away with the rowNum variable

    Cell_array = Split(Sheets(1).Cells(intRow, strRow).Value, Chr(10))


    I hope this helps you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1