SuperNewToThis
New Member
- Joined
- Dec 23, 2017
- Messages
- 4
Hey everyone!
So, what I want to do is essentially repeat a formula that applies to only one row of the sheet to the rest of the rows. I want to count all 999's in a single row, and print this number in a separate variable (named Grit_Tot_Miss). I want to do this for all rows in a given worksheet, no matter the number of rows there are in it (I'm going to be using it on multiple worksheets with varying amounts of rows). Here's a sample of my data:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Grit1[/TD]
[TD]Grit2[/TD]
[TD]Grit3[/TD]
[TD]Grit4[/TD]
[TD]Grit5[/TD]
[TD]Grit6[/TD]
[TD]Grit7[/TD]
[TD]Grit8[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]4[/TD]
[TD]8[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]4[/TD]
[TD]1[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]999[/TD]
[TD]8[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]8[/TD]
[TD]999[/TD]
[TD]999[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]7[/TD]
[TD]5[/TD]
[TD]999[/TD]
[TD]999[/TD]
[TD]8[/TD]
[TD]7[/TD]
[TD]999[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]5[/TD]
[TD]7[/TD]
[TD]4[/TD]
[TD]6[/TD]
[TD]999[/TD]
[TD]8[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]
Also, in case you're wondering, I don't specify actual rows in my code (e.g., "A", "ZZ"), because I want to use this macro on other worksheets that may not have these headings in the same spot. For example, Grit1 may be in the AB column in one sheet, while it is in the CA column in another.
Here's my code so far:
Let me know if anything is unclear. Also, if there are better ways to write the code I have written so far let me know! I'm very new to all this VBA coding, so any help is appreciated!
Thanks!
So, what I want to do is essentially repeat a formula that applies to only one row of the sheet to the rest of the rows. I want to count all 999's in a single row, and print this number in a separate variable (named Grit_Tot_Miss). I want to do this for all rows in a given worksheet, no matter the number of rows there are in it (I'm going to be using it on multiple worksheets with varying amounts of rows). Here's a sample of my data:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Grit1[/TD]
[TD]Grit2[/TD]
[TD]Grit3[/TD]
[TD]Grit4[/TD]
[TD]Grit5[/TD]
[TD]Grit6[/TD]
[TD]Grit7[/TD]
[TD]Grit8[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]4[/TD]
[TD]8[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]4[/TD]
[TD]1[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]999[/TD]
[TD]8[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]8[/TD]
[TD]999[/TD]
[TD]999[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]7[/TD]
[TD]5[/TD]
[TD]999[/TD]
[TD]999[/TD]
[TD]8[/TD]
[TD]7[/TD]
[TD]999[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]5[/TD]
[TD]7[/TD]
[TD]4[/TD]
[TD]6[/TD]
[TD]999[/TD]
[TD]8[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]
Also, in case you're wondering, I don't specify actual rows in my code (e.g., "A", "ZZ"), because I want to use this macro on other worksheets that may not have these headings in the same spot. For example, Grit1 may be in the AB column in one sheet, while it is in the CA column in another.
Here's my code so far:
Sub GRITTEST3()
'
' GRITTEST3 Macro
'
'
'Inputting total missing, total sum, total avg
Cells.Find(What:="Grit8", After:=[A1], LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Offset(0, 1).EntireColumn.Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Offset(0, 1) = "Grit_Tot_Avg"
ActiveCell.Offset(0, 2) = "Grit_Tot_Sum"
ActiveCell.Offset(0, 0) = "Grit_Tot_Miss"
Cells.Find(What:="Grit_Tot_Miss", After:=[A1], LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
'Specify range of values to caclulate formulas
Dim newRange As Range
Set newRange = Range(ActiveCell, ActiveCell.Offset(0, -8))
'Activate Missing column
Cells.Find(What:="Grit_Tot_Miss", After:=[A1], LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
'Count missing data for grit variable
CountMissing = Application.WorksheetFunction.CountIf(newRange.Offset(1, 0), "999")
ActiveCell.Offset(1, 0) = CountMissing
End Sub
Let me know if anything is unclear. Also, if there are better ways to write the code I have written so far let me know! I'm very new to all this VBA coding, so any help is appreciated!
Thanks!