Select a Row where the cursor is active

D

daved37

Hello,

How can I in VBA select a entire rows("number:number") where the cursor
is active...so when the cursor moves through my for next statement it
keeps on selecting the proper rows that I need it too and skipping the
others?

Here's my code so far:

Dim rng As Range

For Each rng In Range("B1:B150")
If rng = "" Then
rng.Activate
Rows("rng").Select ' Here is what doesn't work
Selection.Locked = False
Selection.FormulaHidden = False
Else
rng.Activate
Rows("rng").Select ' Here is what doesn't work
Selection.Locked = True
Selection.FormulaHidden = True

End If

Next

Thanks in advance!

Dave
 
G

Guest

You really don't need the selects. Also rng is a range object. Think of it as
something that point at the cell. It can return the address of the cell or
the value or the anything about the cell (or range of cells)...

Give this a try...

Dim rng As Range

For Each rng In Range("B1:B150")
with rng
If .value = "" Then
.Locked = False
.FormulaHidden = False
Else
.Locked = True
.FormulaHidden = True
End If
End With
Next rng
 
N

Norman Jones

Hi Daved,

Try:

'=============>>
Public Sub Tester()
Dim rng As Range

For Each rng In Range("B1:B150")
With rng
.EntireRow.Locked = .Value <> ""
EntireRow.FormulaHidden = .Value <> ""
End With
Next
End Sub
'<<=============
 
G

Guest

Sorry I missed the entire row in my answer... That being said go with Norman
code with one small change (he missed a dot)

Public Sub Tester()
Dim rng As Range

For Each rng In Range("B1:B150")
With rng
.EntireRow.Locked = .Value <> ""
.EntireRow.FormulaHidden = .Value <> "" 'Missed the dot
End With
Next
End Sub
 
N

Norman Jones

Hi Jim,
Sorry I missed the entire row in my answer... That being said go with
Norman code with one small change (he missed a dot)

Thanks for the catch!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top