+ Reply to Thread
Results 1 to 7 of 7

Trying to run an if then in a cell based on an if then from another cell

Hybrid View

Manaxam Trying to run an if then in a... 12-04-2012, 01:43 AM
protonLeah Re: Trying to run an if then... 12-04-2012, 02:01 AM
Winon Re: Trying to run an if then... 12-04-2012, 02:02 AM
Manaxam Re: Trying to run an if then... 12-04-2012, 02:06 AM
protonLeah Re: Trying to run an if then... 12-04-2012, 03:28 PM
Manaxam Re: Trying to run an if then... 12-04-2012, 10:29 PM
Winon Re: Trying to run an if then... 12-05-2012, 07:44 AM
  1. #1
    Registered User
    Join Date
    10-22-2012
    Location
    Farmington, NM
    MS-Off Ver
    Excel 2003
    Posts
    3

    Trying to run an if then in a cell based on an if then from another cell

    I am trying to run an If Then in column J that will tell me weather or not to color a cell in column G with a sub If Then that will change the color of the cell.

    I must be missing something because the macro runs without an issue but I'm not getting the desired results .... any help would be appreciated.

        Private Sub Worksheet_Activate()
    Dim C As Variant
      Dim CI As Integer
      Dim Col As Variant
      Dim FirstRow As Long
      Dim LastRow As Long
      Dim Rng As Range
      Dim Wks As Worksheet
    
        Col = "J"
        FirstRow = 2
        Set Wks = Worksheets("Pauline")
        LastRow = Wks.Cells(Rows.Count, Col).End(xlUp).Row
        LastRow = IIf(LastRow < FirstRow, FirstRow, LastRow)
            
            Set Rng = Wks.Range(Cells(FirstRow, Col), Cells(LastRow, Col))
                For Each C In Rng
                    If (Range(Cells(FirstRow, Col), Cells(LastRow, Col)) = "Yes") Then
        
                        Col = "G"
                            FirstRow = 2
                            Set Wks = Worksheets("Pauline")
                            LastRow = Wks.Cells(Rows.Count, Col).End(xlUp).Row
                            LastRow = IIf(LastRow < FirstRow, FirstRow, LastRow)
        
                                Set Rng = Wks.Range(Cells(FirstRow, Col), Cells(LastRow, Col))
            
                                If IsDate(C) Then
                                    Select Case Int(Now()) - C
                                        Case Is > 90
                                            CI = 3   'Red
                                        Case Is > 75
                                            CI = 6   'Yellow
                                        Case Is > 60
                                            CI = 4   'Green
                                        Case Else
                                            CI = xlColorIndexNone
                                        End Select
                                    C.Interior.ColorIndex = CI
                                End If
            
                    End If
                Next C

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: Trying to run an if then in a cell based on an if then from another cell

    Explain: Int(Now()) - C
    Ben Van Johnson

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Trying to run an if then in a cell based on an if then from another cell

    Hello Manaxam,

    Welcome to the Forum.

    Why bother with Code? You could use Conditional Formatting for this.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Registered User
    Join Date
    10-22-2012
    Location
    Farmington, NM
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Trying to run an if then in a cell based on an if then from another cell

    protonLeah, The cells I'm coloring are dates and I'm changing the colors based on how past due the dates are compared to today's date (Now).

    Winon, because I'm adding to existing code that works (changing the cell colors based on dates) and am only now wanting to change those colors based on changes in another cells.

    Thank you both for looking at this.

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: Trying to run an if then in a cell based on an if then from another cell

    Try:
    CInt(Now() - C)

  6. #6
    Registered User
    Join Date
    10-22-2012
    Location
    Farmington, NM
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Trying to run an if then in a cell based on an if then from another cell [SOLVED]

    Thank you all for your help. Having grown up with Macros it was my only thought but I on suggestion I went with conditional formatting and after playing with am a true believer. Again, thank you.

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Trying to run an if then in a cell based on an if then from another cell

    Hello Manaxam,

    I went with conditional formatting and after playing with am a true believer
    Yeah, easy!

    Glad you got it sorted out!

+ 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