Hello, I'm trying to write a macro(s) to highlight and sum up particular cells:
1) blank cells
2) cells two columns to the left from a cell containing "TRUE"
Everything should be clear on the scrshot below:
Here is some code I was trying to use (as two separate macros):
and
They won't work the way I want them to though, but at least I tried
Cheers for any help.
--EDIT--
Forgot to mention that the user has to select the range, and then everything is done within it (down the column first, then go to the next row)
1) blank cells
2) cells two columns to the left from a cell containing "TRUE"
Everything should be clear on the scrshot below:
Here is some code I was trying to use (as two separate macros):
Code:
[FONT=Calibri][SIZE=3]Sub MissingValues()[/SIZE][/FONT]
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
[FONT=Calibri][SIZE=3]'[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' MissingValues Macro[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' Finds all missing values within the range specified,[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' highlights the empty cells with blue background colour, font white and bold.[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' Also, counts missing values for every column and row.[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]'[/SIZE][/FONT]
<o:p></o:p>
[FONT=Calibri][SIZE=3]'[/SIZE][/FONT]
<o:p></o:p>
[FONT=Calibri][SIZE=3]Dim valuesRange As Range[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Dim i As Integer[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Dim j As Integer[/SIZE][/FONT]
<o:p></o:p>
<o:p></o:p>
[SIZE=3][FONT=Calibri] On Error Resume Next[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Application.DisplayAlerts = False[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Set valuesRange = Application.InputBox _[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] (Prompt:="Please select the range of values:", _[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Title:="SPECIFY RANGE", Type:=8)[/FONT][/SIZE]
<o:p></o:p>
[SIZE=3][FONT=Calibri] On Error GoTo 0[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Application.DisplayAlerts = True[/FONT][/SIZE]
<o:p></o:p>
[SIZE=3][FONT=Calibri] If valuesRange Is Nothing Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Exit Sub[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Else[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] For Each Cell In valuesRange[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] If IsEmpty(Cell) = True Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' If Len(Trim(Active.Cell)) = 0 Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] With Selection.FormatConditions(1).Font[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] .ThemeColor = xlThemeColorDark1[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End With[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] With Selection.FormatConditions(1).Interior[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] .Color = 12611584[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End With[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Exit For[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End If[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Next Cell[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' For i = 0 To Rows[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' For j = 0 To Cols[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' If active/current.cell Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' ' IsEmpty[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' With Selection.FormatConditions(1).Font[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' .ThemeColor = xlThemeColorDark1[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' End With[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' With Selection.FormatConditions(1).Interior[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' .Color = 12611584[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' End With[/FONT][/SIZE]
[FONT=Calibri][SIZE=3]'[/SIZE][/FONT]
[SIZE=3][FONT=Calibri] ' End If[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' Next j[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] '[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] 'Next i[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End If[/FONT][/SIZE]
<o:p></o:p>
<o:p></o:p>
[FONT=Calibri][SIZE=3]End Sub[/SIZE][/FONT]
and
Code:
[FONT=Calibri][SIZE=3]Sub Outliers()[/SIZE][/FONT]
<o:p></o:p>
[FONT=Calibri][SIZE=3]'[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' Finds the outliers basing on the z-value and[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' highlights the cells - the corresponding values (two columns to the left), not TRUEs[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' with yellow background colour, changing the font colour to red and bolding it.[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' Also, counts outliers for every column and per each row as well.[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]'[/SIZE][/FONT]
<o:p></o:p>
[FONT=Calibri][SIZE=3]'[/SIZE][/FONT]
[SIZE=3][FONT=Calibri] Dim valuesRange As Range[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Set valuesRange = Application.InputBox _[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] (Prompt:="Please select the range of values:", _[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Title:="SPECIFY RANGE", Type:=8)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] valuesRange.Select[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Selection.FormatConditions.Add Type:=xlTextString, String:="TRUE", _[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] TextOperator:=xlContains[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] With Selection.FormatConditions(1).Font[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] .Color = -16776961[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End With[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] With Selection.FormatConditions(1).Interior[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] .Color = 65535[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End With[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] ' Selection.FormatConditions(1).StopIfTrue = False[/FONT][/SIZE]
<o:p></o:p>
[FONT=Calibri][SIZE=3]End Sub[/SIZE][/FONT]
They won't work the way I want them to though, but at least I tried
Cheers for any help.
--EDIT--
Forgot to mention that the user has to select the range, and then everything is done within it (down the column first, then go to the next row)
Last edited: