+ Reply to Thread
Results 1 to 2 of 2

Need help with looping function

  1. #1
    Mike
    Guest

    Need help with looping function

    Hi,
    Im not really a vba programmer, so i need some help with this one.
    I have large excel sheet with customer which I summarize using
    subtotal.

    I want a function that does the following :
    if total then check the total sum for this row, if negative number set
    background for the whole
    row = yellow.

    I got started but then i got stuck :

    Sub TrailMyNegativeNumbers()
    '
    ' TrailMyNegativeNumbers Macro
    ' Macro recorded 15.02.2006 by Mikal Skaaren
    '
    ' Keyboard Shortcut: Ctrl+z
    '

    Dim c As Range

    ' Select the range for the first criteria
    Range("A2: A22").Select

    For Each c In Selection.Cells

    MsgBox (c.Value)

    ' If c.Value="" then TOTAL
    If (c.Value = "") Then

    ' Get a reference to the right
    ' Column in the selected row
    ' and see if that number > 0
    '

    ' If negative set the background color
    ' = yellow

    c.EntireRow.Select
    With Selection.Font
    ' .ColorIndex = 12
    End With

    End If
    Next


    End Sub

    Could anybody help me with this function pleease?

    BR
    Mike


  2. #2
    Bob Phillips
    Guest

    Re: Need help with looping function

    Mike,

    It would be easier to use conditional formatting to set the colour.

    What exactly is your condition that triggers a yellow colour?

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Mike" <mikal_sk@yahoo.no> wrote in message
    news:1139997394.148646.255620@z14g2000cwz.googlegroups.com...
    > Hi,
    > Im not really a vba programmer, so i need some help with this one.
    > I have large excel sheet with customer which I summarize using
    > subtotal.
    >
    > I want a function that does the following :
    > if total then check the total sum for this row, if negative number set
    > background for the whole
    > row = yellow.
    >
    > I got started but then i got stuck :
    >
    > Sub TrailMyNegativeNumbers()
    > '
    > ' TrailMyNegativeNumbers Macro
    > ' Macro recorded 15.02.2006 by Mikal Skaaren
    > '
    > ' Keyboard Shortcut: Ctrl+z
    > '
    >
    > Dim c As Range
    >
    > ' Select the range for the first criteria
    > Range("A2: A22").Select
    >
    > For Each c In Selection.Cells
    >
    > MsgBox (c.Value)
    >
    > ' If c.Value="" then TOTAL
    > If (c.Value = "") Then
    >
    > ' Get a reference to the right
    > ' Column in the selected row
    > ' and see if that number > 0
    > '
    >
    > ' If negative set the background color
    > ' = yellow
    >
    > c.EntireRow.Select
    > With Selection.Font
    > ' .ColorIndex = 12
    > End With
    >
    > End If
    > Next
    >
    >
    > End Sub
    >
    > Could anybody help me with this function pleease?
    >
    > BR
    > Mike
    >




+ 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