Hi, I am trying to do a tricky part and I really need help here.
I am trying to check how many blanks there are below the current cell, and if there is more than 6, then run some code. If there is not more than 6, I will check for 5, then 4 and so on until 0. I thought I could add this as an IF statement for 6 blanks then run some code, then a new IF statement for 5 blanks and run the same code and so on.. But if there is an even better solution containing less code that is of course even better.
There is also some other criterias that has to be fulfilled. These are that the first column of the row has to be the same as the value of "D35" and that range E45 has to be the value "Great". These work as they should, I only need help with the checking of blanks.
I have this code right now, but I dont know how to check if there is more than 6 blanks on the range below:
If .Cells(R, col) = Range("D35") And Range("E35").Value = "Great" And .Cells(R, col).Offset(0, 2).Resize(20, 0) >= 6 blanks in this range Then
See the full code below:
I am trying to check how many blanks there are below the current cell, and if there is more than 6, then run some code. If there is not more than 6, I will check for 5, then 4 and so on until 0. I thought I could add this as an IF statement for 6 blanks then run some code, then a new IF statement for 5 blanks and run the same code and so on.. But if there is an even better solution containing less code that is of course even better.
There is also some other criterias that has to be fulfilled. These are that the first column of the row has to be the same as the value of "D35" and that range E45 has to be the value "Great". These work as they should, I only need help with the checking of blanks.
I have this code right now, but I dont know how to check if there is more than 6 blanks on the range below:
If .Cells(R, col) = Range("D35") And Range("E35").Value = "Great" And .Cells(R, col).Offset(0, 2).Resize(20, 0) >= 6 blanks in this range Then
See the full code below:
Code:
Sub Add_data()
Dim col As Variant
Dim BlankRows As Long
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
col = "Z"
StartRow = 1
BlankRows = 1
LastRow = Cells(Rows.Count, col).End(xlUp).Row
Application.ScreenUpdating = False
With ActiveSheet
For R = LastRow To StartRow + 1 Step -1
If .Cells(R, col) = Range("D35") And Range("E35").Value = "Great"[B] And .Cells(R, col).Offset(0, 2).Resize(20, 0) = ""[/B] Then
.Cells(R, col).Offset(0, 0).Value = Range("D35").Value
.Cells(R, col).Offset(0, 2).Value = Range("A35").Value
.Cells(R, col).Offset(0, 3).Value = Range("B35").Value
Range("BJ33").Copy .Cells(R, col).Offset(0, 1)
End If
Next R
End With
Application.ScreenUpdating = True
End Sub
Last edited: