Results 1 to 4 of 4

Code is putting formatting cells as text so that VB function and Sumproduct #Value! error

Threaded View

  1. #1
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Code is putting formatting cells as text so that VB function and Sumproduct #Value! error

    Hello valuable Guru's,

    I have this all put together nicely with the help of so many contributors but I have a slight problem. The code that runs is apparently formatting the cell or data as text so that my VB ColorFunction code and my Sumproduct coding on the columns is finding text resulting in #value! errors. I fixed a portion of it (a column) with a solution of using Text to Columns and selecting general format at the end that was given to me by @FDibbins a week or so ago and it proved that it would correct it. However I have 365 columns to do this on so could use help with finding the problem in the code. If need be I can scrub the names out of the file and attach it but other wise I will attach the code below and a picture of the problem. I think that possibly the culprit is the Sub Green_is_1 () subroutine possibly not formatting correct as this is the latest codes that was added to put 1s in the cells so that I could get totals. However it did work on a mock up it was installed in and now back in the source file it is not. There was no difference in the code as I just copied the afforementioned subroutine in to the source file code. The rest was already there and the mock up just had a copy of this code. The mock up was just a copy of the original worksheet with some of the formulas in the cells outside the range that are used were copy then pasted values so that the formulas didn't return errors since the source data wasn't available or simply a static copy of the source data. Ok so enough of my confusion. Here is the module 1 code.

    Function ColorFunction(rRange As Range)
    Dim rCell As Range, lCol As Long, vResult
    For Each rCell In rRange    '.SpecialCells(xlCellTypeVisible).Cells
        If rCell.Interior.Color = vbGreen And Not Rows(rCell.Row).Hidden Then
            vResult = 1 + vResult
        End If
    Next rCell
    ColorFunction = vResult
    End Function
    Sub test()
    Dim lr, x, l, j, myrest, stcol, stcol2
    Application.ScreenUpdating = False
    lr = Range("F" & Rows.Count).End(xlUp).Row
    Range("N17", "XFD" & lr).ClearContents
    For x = 17 To lr
        Range("N" & x, "XFD" & x).Interior.Pattern = xlNone
        If Range("G" & x) >= Range("N11") Then
            stcol = Application.Match(Range("G" & x), Range("A11", "XFD11"), 0) + 1
            edat = stcol - 1
            stcol2 = stcol + Range("M" & x).Value
            Do While Year(Cells(11, stcol)) = Range("C2")
                Cells(x, stcol).Resize(, Range("M" & x).Value).Interior.Color = RGB(0, 112, 192)
                Cells(x, stcol2).Resize(, Range("L" & x)).Interior.Color = vbGreen
                stcol = stcol + (Range("M" & x) + Range("L" & x))
                stcol2 = stcol2 + (Range("M" & x) + Range("L" & x))
            Loop
            bdat = Application.Match(Range("F" & x), Range("A11", "XFD11"), 0)
            If Not IsError(bdat) Then
                Range(Cells(x, bdat), Cells(x, edat)).Interior.Color = vbGreen
            Else
                Range(Cells(x, 14), Cells(x, edat)).Interior.Color = vbGreen
            End If
        End If
        If Range("G" & x) < Range("N11") Then
            myrest = (Range("N11") - Range("G" & x)) Mod (Range("M" & x) + Range("L" & x))
            If myrest < Range("M" & x) Then
                Cells(x, 14).Resize(, (Range("M" & x)) - myrest).Interior.Color = RGB(0, 112, 192)
                Cells(x, 14 + (Range("M" & x)) - myrest).Resize(, Range("L" & x)).Interior.Color = vbGreen
                stcol = 14 + (Range("M" & x) - myrest) + Range("L" & x)
                stcol2 = stcol + Range("M" & x)
                Do While Year(Cells(11, stcol)) = Range("C2")
                    Cells(x, stcol).Resize(, Range("M" & x)).Interior.Color = RGB(0, 112, 192)
                    Cells(x, stcol2).Resize(, Range("L" & x)).Interior.Color = vbGreen
                    stcol = stcol + Range("M" & x) + Range("L" & x)
                    stcol2 = stcol2 + Range("M" & x) + Range("L" & x)
                Loop
            Else
                Cells(x, 14).Resize(, ((Range("L" & x) + Range("M" & x)) - myrest)).Interior.Color = vbGreen
                stcol = (14 + Range("L" & x) + Range("M" & x)) - myrest
                stcol2 = stcol + Range("L" & x)
                Do While Year(Cells(11, stcol)) = Range("C2")
                    Cells(x, stcol).Resize(, Range("M" & x)).Interior.Color = RGB(0, 112, 192)
                    Cells(x, stcol2).Resize(, Range("L" & x)).Interior.Color = vbGreen
                    stcol = stcol + Range("M" & x) + Range("L" & x)
                    stcol2 = stcol2 + Range("M" & x) + Range("L" & x)
                Loop
            End If
        End If
    Next
    Range("NO17", "XFD" & lr).Interior.Pattern = xlNone
    Range("NO17", "XFD" & lr).ClearContents
        'Add to last row + 2 a count of all Green and format cell and font
        Range("N" & lr + 2, "NN" & lr + 2).FormulaR1C1 = "=Colorfunction(R17C:R[-1]C)"
        Range("N" & lr + 2, "NN" & lr + 2).Interior.Color = RGB(0, 32, 96)
        Range("N" & lr + 2, "NN" & lr + 2).Font.Color = RGB(255, 255, 0)
    
        
    End Sub
    Sub Reset()
    
    Range("N17:NN300").ClearContents
    Range("N17").Select
    
    End Sub
    Sub Green_is_1()
        
          Range("N17").Select
        With Application.FindFormat.Interior
            .Color = 65280
        End With
        
        Range("N17:NN300").Replace What:="", Replacement:="1", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    
    End Sub

    See attached picture. The picture is the top rows Sumproduct command. The ColorFunction subroutine is at row 152 so I didn't capture it but is basically same result.


    Thank you all in advance!
    Attached Images Attached Images

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Exclude cells containing text from SUMPRODUCT function
    By Uomoviso in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-17-2016, 09:20 AM
  2. Error putting excel formula in the cell by vba code
    By quizexcel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-28-2016, 06:33 AM
  3. putting a function into VB code
    By Pontiac in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-05-2015, 10:18 PM
  4. Replies: 3
    Last Post: 12-15-2013, 04:01 AM
  5. [SOLVED] VBA - putting a formula in cells but its got a syntax error please help!! :-)
    By LauraWork in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2013, 08:06 AM
  6. putting an if condition based on text in a cell - runtime error 13: type mismatch
    By rbs123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-29-2013, 04:02 AM
  7. Error putting horizontal series of cells into array .....why?
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-23-2011, 10:32 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