Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Select a Row where the cursor is active

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Select a Row where the cursor is active

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

--
HTH...

Jim Thomlinson


" wrote:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Select a Row where the cursor is active

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
'<<=============


---
Regards,
Norman



wrote in message
oups.com...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Select a Row where the cursor is active

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

--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

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

--
HTH...

Jim Thomlinson


" wrote:

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Select a Row where the cursor is active

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!


---
Regards,
Norman


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Row select mode to highlight active row of active cell Bart Fay[_2_] Excel Discussion (Misc queries) 0 May 11th 10 09:34 PM
keep active sheet view and cursor position killa47 Excel Worksheet Functions 0 November 8th 05 09:20 AM
Cursor keys move active cell or scroll screen, how do I select whi Rob Croft Excel Discussion (Misc queries) 1 June 18th 05 11:51 PM
Changing active selection cursor Mistaken Creation Excel Discussion (Misc queries) 3 May 27th 05 10:06 PM
Identifying cursor in active spreedsheet C Ambrose Excel Worksheet Functions 9 May 24th 05 11:36 PM


All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"