+ Reply to Thread
Results 1 to 10 of 10

Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    989

    Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    Hello,

    I was advised that the cells in a sheet cannot be the same as a Textbox in a Userform - However can the formatting be passed to a cell from the textbox in a Userform?

    JOhn

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

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    What do you mean by formatting? Are you trying to choose the font or fill color...?
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    989

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    Cell Field color

  4. #4
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    989

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    Example of code in textbox in Userform

    Private Sub txtacw_Change()
    
      Dim sValue As String
      Dim xValue As Double
      
      'Get the value in the textbox as a string
      sValue = Me.txtacw.Value
      
      'Color the TextBox BackGround Color if the value is numeric
      If IsNumeric(sValue) Then
        xValue = CDbl(sValue)
        If xValue >= 50# And xValue < 100# Then
          Me.txtacw.BackColor = RGB(255, 246, 143) 'Yellow
        ElseIf xValue >= 100# Then
          Me.txtacw.BackColor = RGB(240, 128, 128) 'Red
        Else
          Me.txtacw.BackColor = RGB(152, 251, 152) 'Green
        End If
      End If
      
    End Sub

  5. #5
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    989

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    Passing it back to my sheet:

    Dim fullname As String, _
        lACRow As Variant
        lACRow = Me.lstMyData.ListIndex
    
        With Sheets("EmployeeData")
        
            'find the employee name in record base
            Set lACRow = .Range("A:A").Find(txtfullname.Text)
            
            If lACRow Is Nothing Then
                MsgBox "Name not found"
                Exit Sub
            End If
            
            .Range("A" & lACRow.Row).Resize(columnsize:=11).Value = Array( _
                    txtfullname.Text, _
                    txthiredate.Text, _
                    txtaht.Text, _
                    txtacw.Text, _
                    txtquality.Text, _
                    cbodepartments.Text, _
                    txtadherence.Text, _
                    txtvoc.Text, _
                    txtnps.Text, _
                    txtfcr.Text, _
                    cboteams.Text)
        End With
    End Sub
    Any Thoughts?

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

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    Use something like this:
    Dim j As Long
    j = TextBox1.BackColor
    Range("A1").Interior.Color = j

  7. #7
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    989

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    ProtonLeah,

    Is this placed in a current code I have above or is this an addition to the code?

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

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    I'm still guessing, but try:
    Option Explicit
    Dim fullname As String, _
        lACRow As Variant
        lACRow = Me.lstMyData.ListIndex
    
        With Sheets("EmployeeData")
        
            'find the employee name in record base
            Set lACRow = .Range("A:A").Find(txtfullname.Text)
            
            If lACRow Is Nothing Then
                MsgBox "Name not found"
                Exit Sub
            End If
            
            .Range("A" & lACRow.Row).Resize(columnsize:=11).Value = Array( _
                    txtfullname.Text, _
                    txthiredate.Text, _
                    txtaht.Text, _
                    txtacw.Text, _
                    txtquality.Text, _
                    cbodepartments.Text, _
                    txtadherence.Text, _
                    txtvoc.Text, _
                    txtnps.Text, _
                    txtfcr.Text, _
                    cboteams.Text)
    '----------------------------------------
    ' assuming you want the cell to have the same color as "txtquality", for example, then try:
            .Range("A" & lACRow.Row).Interior.Color = txtquality.BackColor
    '----------------------------------------
        End With
    End Sub

  9. #9
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    989

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    ProtonLeah,

    This diod not effect the color of the Quality Cell in the EmployeeData Sheet

    John

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

    Re: Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?

    Maybe a sample workbook with sensitive info deleted. This is what I think you are asking for: The form has tow textboxes and the button fills the active cell and the below right with the textbox backcolors.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. conditional formatting with passed in values
    By charles1239 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 12-01-2012, 10:32 PM
  2. Conditional formatting based on entered dated and how much time has passed
    By sanchez7315 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-17-2012, 12:07 AM
  3. Conditional formatting for dates/time x hours passed
    By Sirodot in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-18-2012, 11:04 AM
  4. Replies: 3
    Last Post: 06-29-2011, 01:58 PM
  5. Conditional Formatting based on date passed
    By windme in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-05-2008, 10:54 AM

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