View Single Post
 
Old 06-11-2015, 08:17 PM
excelledsoftware excelledsoftware is offline Windows 8 Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

That long line with the countif drives me crazy. Here is a revised version that removes that long line but does the very same thing.
Code:
Option Explicit
Sub CountTrueValues()
  'Inserts a column to the right of C and then runs
  'a countif to see how many times the phrase true
  'is entered in the columns
  
  Dim CheckRow As Long, LastRow As Long, Tot As Integer
  Dim LastCol As String, CountRange As String
  
  'Insert a column
  Range("D:D").Insert
  Range("D1").Value = "TRUE Count"
  
  'Identify where to stop
  LastRow = Range("C2").End(xlDown).Row
  LastCol = Range("A1").End(xlToRight).Address
  LastCol = Mid(LastCol, 2) 'remove first $
  LastCol = Mid(LastCol, 1, InStr(1, LastCol, "$") - 1) 'remove the row

  'Go through the data and enter a value
  For CheckRow = 2 To LastRow
    CountRange = "E" & CheckRow & ":" & LastCol & CheckRow
    Tot = WorksheetFunction.CountIf(Range(CountRange), "true")
    Range("D" & CheckRow).Value = Tot
  Next CheckRow
  
  MsgBox "done"
  
End Sub
Reply With Quote