spartanjim
New Member
- Joined
- Jan 29, 2012
- Messages
- 2
I'm working in XL07 on Win7.
The workbook has two worksheets "Data" & "Crunch". "Data" contains the raw data-range B1:U50. "Crunch" is the processing worksheet. Row 1 is a header row. Columns A-D are empty. Column E (rows 2-81) contain the numbers 1-80.
The macro is intended to run in "Crunch". I need to add the CountIf function in every cell/row filling the range F2:BC81. A loop does the trick for me to fill the rows in each column but I don't know how to move the loop down each column without creating a new loop.
A section of the code is below. Notice a majority of the code is the same, the copy in red is variable from loop to loop. I need to repeat this loop through column "BC" (50 times in total). My guess is there is a way to write this code one time instead of 50 times adjusting the variable components.
Thank you
Jim
The workbook has two worksheets "Data" & "Crunch". "Data" contains the raw data-range B1:U50. "Crunch" is the processing worksheet. Row 1 is a header row. Columns A-D are empty. Column E (rows 2-81) contain the numbers 1-80.
The macro is intended to run in "Crunch". I need to add the CountIf function in every cell/row filling the range F2:BC81. A loop does the trick for me to fill the rows in each column but I don't know how to move the loop down each column without creating a new loop.
A section of the code is below. Notice a majority of the code is the same, the copy in red is variable from loop to loop. I need to repeat this loop through column "BC" (50 times in total). My guess is there is a way to write this code one time instead of 50 times adjusting the variable components.
Code:
'Find total # of records and then store in variable
totalrecords = ActiveSheet.UsedRange.Rows.Count
'CountIf Statement
For Row = totalrecords To 2 Step -1
If Cells(Row, 5).Value <> "0" Then
Cells(Row, [COLOR="Red"]6[/COLOR]).Value = "=COUNTIF(Data!$B$1:$U$[COLOR="red"]1[/COLOR], E" & Row & ")"
End If
Next Row
'Find total # of records and then store in variable
totalrecords = ActiveSheet.UsedRange.Rows.Count
'CountIf Statement
For Row = totalrecords To 2 Step -1
If Cells(Row, 5).Value <> "0" Then
Cells(Row, [COLOR="red"]7[/COLOR]).Value = "=COUNTIF(Data!$B$1:$U$[COLOR="red"]2[/COLOR], E" & Row & ")"
End If
Next Row
'Find total # of records and then store in variable
totalrecords = ActiveSheet.UsedRange.Rows.Count
'CountIf Statement
For Row = totalrecords To 2 Step -1
If Cells(Row, 5).Value <> "0" Then
Cells(Row, [COLOR="red"]8[/COLOR]).Value = "=COUNTIF(Data!$B$1:$U$[COLOR="red"]3[/COLOR], E" & Row & ")"
End If
Next Row
'Find total # of records and then store in variable
totalrecords = ActiveSheet.UsedRange.Rows.Count
'CountIf Statement
For Row = totalrecords To 2 Step -1
If Cells(Row, 5).Value <> "0" Then
Cells(Row, [COLOR="red"]9[/COLOR]).Value = "=COUNTIF(Data!$B$1:$U$[COLOR="red"]4[/COLOR], E" & Row & ")"
End If
Next Row
Thank you
Jim