+ Reply to Thread
Results 1 to 3 of 3

"if" statement within a macro

  1. #1
    Mili
    Guest

    "if" statement within a macro

    I have a list of employee and when the button "update employees" is selected
    I want the macro to cut and paste employess who are marked not current to
    another page. I don't know how to use an IF statement within a macro. Please
    help

  2. #2
    Bob Phillips
    Guest

    Re: "if" statement within a macro


    Dim iLastRow As Long
    Dim i As Long
    Dim rng As Range
    iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To iLastRow
    If Cells(i, "A").Value = "Not Current" Then
    If rng Is Nothing Then
    Set rng = Rows(i)
    Else
    Set rng = Union(rng, Rows(i))
    End If
    End If
    Next i

    If Not rng Is Nothing Then
    rng.Copy Destination:=Worksheets("Sheet2").Range("A1")
    End If


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Mili" <[email protected]> wrote in message
    news:[email protected]...
    > I have a list of employee and when the button "update employees" is

    selected
    > I want the macro to cut and paste employess who are marked not current to
    > another page. I don't know how to use an IF statement within a macro.

    Please
    > help




  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Mili,

    The IF statement is a basic construct used by all programming languages. Form machine code to high level compiler languages, this statement is used to make a 2 decisions based on the result of the expression being tested. If the expression tests true do something, and do something else if it is false.

    If Example:
    If A = B Then
    'Code for True result goes here
    Else
    'Code for False result goes here
    End If

    Sincerely,
    Leith Ross

+ 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