ThePangloss
New Member
- Joined
- Jun 19, 2015
- Messages
- 40
Hey guys, so I'm trying to fix a set of data column by column. So for example I have
[TABLE="width: 500"]
<tbody>[TR]
[TD]Pass[/TD]
[TD]Score[/TD]
[TD]Age[/TD]
[TD]Gender[/TD]
[/TR]
[TR]
[TD]No[/TD]
[TD]40[/TD]
[TD]21[/TD]
[TD]Male[/TD]
[/TR]
[TR]
[TD]Yes[/TD]
[TD]92[/TD]
[TD]19[/TD]
[TD]Female[/TD]
[/TR]
[TR]
[TD]Yes[/TD]
[TD]87[/TD]
[TD]45[/TD]
[TD]Male[/TD]
[/TR]
[TR]
[TD]No[/TD]
[TD]69[/TD]
[TD]60[/TD]
[TD]Female[/TD]
[/TR]
[TR]
[TD]Yes[/TD]
[TD]72[/TD]
[TD]37[/TD]
[TD]Female[/TD]
[/TR]
</tbody>[/TABLE]
and I want
[TABLE="width: 500"]
<tbody>[TR]
[TD]Pass[/TD]
[TD]Score[/TD]
[TD]Age[/TD]
[TD]Gender[/TD]
[/TR]
[TR]
[TD]N[/TD]
[TD]40-49[/TD]
[TD]20-25[/TD]
[TD]M[/TD]
[/TR]
[TR]
[TD]Y[/TD]
[TD]90-100[/TD]
[TD]15-19[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD]Y[/TD]
[TD]80-89[/TD]
[TD]40-45[/TD]
[TD]M[/TD]
[/TR]
[TR]
[TD]N[/TD]
[TD]60-69[/TD]
[TD]60-65[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD]Y[/TD]
[TD]70-79[/TD]
[TD]36-39[/TD]
[TD]F[/TD]
[/TR]
</tbody>[/TABLE]
pasted about 20 columns to the right of the original data
I wanted to create a macro that selects this whole range, checks if the first column's header is "Pass", and then calls a private sub that I've create using Select Case to fix "N" to "N" and "Yes" to "Y". Then it'll work to the next column. I just need to have it check the first column because I have various sheets of data all organized the same way. If it checks the first column and it does indeed say "Pass" it'll run the macro because the rest of the columns are all the same.
After it runs the first column it'll run the private sub for score to put it in buckets of tens let's say. So 40 would go into "40-50", 92 into "90-100". And so on for each column
I tried using
but this means I have to manually retype the for with statement and have a long list of code. Is there any way to shorten this code using loops?
Any help would be appreciated!
[TABLE="width: 500"]
<tbody>[TR]
[TD]Pass[/TD]
[TD]Score[/TD]
[TD]Age[/TD]
[TD]Gender[/TD]
[/TR]
[TR]
[TD]No[/TD]
[TD]40[/TD]
[TD]21[/TD]
[TD]Male[/TD]
[/TR]
[TR]
[TD]Yes[/TD]
[TD]92[/TD]
[TD]19[/TD]
[TD]Female[/TD]
[/TR]
[TR]
[TD]Yes[/TD]
[TD]87[/TD]
[TD]45[/TD]
[TD]Male[/TD]
[/TR]
[TR]
[TD]No[/TD]
[TD]69[/TD]
[TD]60[/TD]
[TD]Female[/TD]
[/TR]
[TR]
[TD]Yes[/TD]
[TD]72[/TD]
[TD]37[/TD]
[TD]Female[/TD]
[/TR]
</tbody>[/TABLE]
and I want
[TABLE="width: 500"]
<tbody>[TR]
[TD]Pass[/TD]
[TD]Score[/TD]
[TD]Age[/TD]
[TD]Gender[/TD]
[/TR]
[TR]
[TD]N[/TD]
[TD]40-49[/TD]
[TD]20-25[/TD]
[TD]M[/TD]
[/TR]
[TR]
[TD]Y[/TD]
[TD]90-100[/TD]
[TD]15-19[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD]Y[/TD]
[TD]80-89[/TD]
[TD]40-45[/TD]
[TD]M[/TD]
[/TR]
[TR]
[TD]N[/TD]
[TD]60-69[/TD]
[TD]60-65[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD]Y[/TD]
[TD]70-79[/TD]
[TD]36-39[/TD]
[TD]F[/TD]
[/TR]
</tbody>[/TABLE]
pasted about 20 columns to the right of the original data
I wanted to create a macro that selects this whole range, checks if the first column's header is "Pass", and then calls a private sub that I've create using Select Case to fix "N" to "N" and "Yes" to "Y". Then it'll work to the next column. I just need to have it check the first column because I have various sheets of data all organized the same way. If it checks the first column and it does indeed say "Pass" it'll run the macro because the rest of the columns are all the same.
After it runs the first column it'll run the private sub for score to put it in buckets of tens let's say. So 40 would go into "40-50", 92 into "90-100". And so on for each column
I tried using
Code:
Dim List as Range
Dim counter As Integer
counter = 0
For with List in Range("A2:A5").Offset(0, counter)
List.Offset(0,20).Value
Call pass(Link As range)
End with
counter = counter + 1
counter = 0
For with List in Range("A2:A5").Offset(0, counter)
List.Offset(0,20).Value
Call score(List As range)
End with
End Sub
'Where the private sub is simply
Private Sub pass()
Select Case List
Case "Yes"
.Value = "Y"
Case "No"
.Value = "N"
End Select
Private sub score()
Select Case List
Case 0 to 9
.Value = "0 to 9"
Case 10 to 19
.Value = "10 to 19"
'...repeated
End Select
Any help would be appreciated!
Last edited: