mike637
asked on
vba go to next unlocked cell in range
Hello Experts,
I would like to have my vba code search through the range("C4:G66") and go to the next unlocked unused cell.
I find ways to go through rows or columns - but I need it to do both.
Please Help!!
I would like to have my vba code search through the range("C4:G66") and go to the next unlocked unused cell.
I find ways to go through rows or columns - but I need it to do both.
Please Help!!
ASKER
Hello,
How do I get this code to go through the range and select the cell that is [not locked] and value = 0?
I have played with the code, but it is going to the last cell in the range [G66]
Thanks
How do I get this code to go through the range and select the cell that is [not locked] and value = 0?
I have played with the code, but it is going to the last cell in the range [G66]
Thanks
You mean this?
Sub Sample()
Dim rng As Range
Dim cl As Range
Set rng = Sheets("Sheet1").Range("C4:G66")
For Each cl In rng.Cells
If cl.Locked = False And Len(Trim(cl.Value)) = 0 Then
cl.Select
Exit For
End If
Next
End Sub
ASKER
Hello SinddharthRout:
I am almost there - I just need it to scroll the column first - instead of the row.
If I have data in C4 - It is going to D4. I need it to scroll down to the next "free" cell in the column which would be C5 ( if C4 has data ). If Column C is complete, then it should go to column D.
Can this be done?
mike637
I am almost there - I just need it to scroll the column first - instead of the row.
If I have data in C4 - It is going to D4. I need it to scroll down to the next "free" cell in the column which would be C5 ( if C4 has data ). If Column C is complete, then it should go to column D.
Can this be done?
mike637
You mean like this?
Sub Sample()
Dim rng As Range
Set rng = Sheets("Sheet1").Range("C4:G66")
For j = rng.Column To (rng.Column + rng.Columns.Count - 1)
For i = rng.Row To (rng.Row + rng.Rows.Count - 1)
If Cells(i, j).Locked = False And Len(Trim(Cells(i, j).Value)) = 0 Then
Cells(i, j).Select
Exit For
Next i
Next j
End Sub
ASKER
Hello SinddharthRout:
I am getting an error message at line 9
Next i statement
Compile error: Next without For
I am getting an error message at line 9
Next i statement
Compile error: Next without For
Sorry.
Try this
Sid
Try this
Sub Sample()
Dim rng As Range
Set rng = Sheets("Sheet1").Range("C4:G66")
For j = rng.Column To (rng.Column + rng.Columns.Count - 1)
For i = rng.Row To (rng.Row + rng.Rows.Count - 1)
If Cells(i, j).Locked = False And Len(Trim(Cells(i, j).Value)) = 0 Then
Cells(i, j).Select
Exit For
End If
Next i
Next j
End Sub
Sid
Wait, I think, I just spotted another error,
Sid
Sid
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked Excellent!!
Many Thanks.
Many Thanks.
Open in new window
Sid