Hello everyone,
I am familiar with a few coding languages, including PHP, C++, etc, however I am new to Excel and VBA. I am attempting to create a do-while/do-until loop which stays in the same column, and keeps descending row to row until it hits a Gray-filled cell, at which point it takes the value of that cell and returns it. The data looks something like this:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Sam[/TD]
[TD]4[/TD]
[TD]7[/TD]
[TD]34[/TD]
[TD]4[/TD]
[TD]3[/TD]
[TD]5[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]5[/TD]
[TD]4[/TD]
[TD]44[/TD]
[TD]34[/TD]
[TD]5[/TD]
[TD]8[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]3[/TD]
[TD]34[/TD]
[TD]22[/TD]
[TD]34[/TD]
[TD]5[/TD]
[TD]68[/TD]
[TD]85[/TD]
[/TR]
[TR]
[TD]Mark[/TD]
[TD]234[/TD]
[TD]43[/TD]
[TD]23[/TD]
[TD]65[/TD]
[TD]345[/TD]
[TD]23[/TD]
[TD]434[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]234[/TD]
[TD]234[/TD]
[TD]65[/TD]
[TD]45[/TD]
[TD]3[/TD]
[TD]45[/TD]
[TD]65[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]745[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]63[/TD]
[TD]345[/TD]
[TD]4[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
(It was easier in this post to change the font color instead of the fill color, but you get the idea). Also, the number of rows between names varies. What I have written so far is this:
Should I use a function here, or sub? Also, I keep getting an "Application-defined or object-defined error" message. What am I doing wrong/is there an easier way?
Thanks in advance for any help with this, I greatly appreciate it!
I am familiar with a few coding languages, including PHP, C++, etc, however I am new to Excel and VBA. I am attempting to create a do-while/do-until loop which stays in the same column, and keeps descending row to row until it hits a Gray-filled cell, at which point it takes the value of that cell and returns it. The data looks something like this:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Sam[/TD]
[TD]4[/TD]
[TD]7[/TD]
[TD]34[/TD]
[TD]4[/TD]
[TD]3[/TD]
[TD]5[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]5[/TD]
[TD]4[/TD]
[TD]44[/TD]
[TD]34[/TD]
[TD]5[/TD]
[TD]8[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]3[/TD]
[TD]34[/TD]
[TD]22[/TD]
[TD]34[/TD]
[TD]5[/TD]
[TD]68[/TD]
[TD]85[/TD]
[/TR]
[TR]
[TD]Mark[/TD]
[TD]234[/TD]
[TD]43[/TD]
[TD]23[/TD]
[TD]65[/TD]
[TD]345[/TD]
[TD]23[/TD]
[TD]434[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]234[/TD]
[TD]234[/TD]
[TD]65[/TD]
[TD]45[/TD]
[TD]3[/TD]
[TD]45[/TD]
[TD]65[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]745[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]63[/TD]
[TD]345[/TD]
[TD]4[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
(It was easier in this post to change the font color instead of the fill color, but you get the idea). Also, the number of rows between names varies. What I have written so far is this:
Code:
Function checkFill()
Dim i As Integer
Dim AHT As Integer
i = 0
Do While Cells(i, 5).Interior.ColorIndex > 0
If Cells(i, 5).Interior.ColorIndex = 16 Then
AHT = Cells(i, 5).Value
Exit Do
End If
i = i + 1
Loop
End Function
Should I use a function here, or sub? Also, I keep getting an "Application-defined or object-defined error" message. What am I doing wrong/is there an easier way?
Thanks in advance for any help with this, I greatly appreciate it!