Selection Code

  • Thread starter Thread starter bw
  • Start date Start date
B

bw

Consider the following:
Range(Cells(CurrentRow, 1), Cells(CurrentRow, 7)).Select
Selection.Locked = False
Selection.FormulaHidden = False
Cells(CurrentRow, 9).Select
Selection.Locked = False
Selection.FormulaHidden = False

Is there a way to combine the two select statements into just one?

Thanks,
Bernie
 
With Range(Cells(CurrentRow, 1), Cells(CurrentRow, 7))
.Locked = False
.FormulaHidden = False
End With
With Cells(CurrentRow, 9)
.Locked = False
.FormulaHidden = False
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Hi,
The following (not tested) doesn't really combine the two operations but it
does avoid the need to select

With Range(Cells(CurrentRow, 1), Cells(CurrentRow, 7))
.Locked = False
.FormulaHidden = False
End With
With Cells(CurrentRow, 9)
.Locked = False
.FormulaHidden = False
End With

Don
 
Thanks for the replies!

I should have been more specific in my question.
The following two select statements:

Range(Cells(CurrentRow, 1), Cells(CurrentRow, 7)).Select
Cells(CurrentRow, 9).Select

can be combined into a single statement as follows:
Range("A1:G1,I1").Select

So how do I express the single statement using the variable "CurrentRow"?

Thanks,
Bernie
 
Bernie,

If you are always selecting columns A to G and column I you could do it like
this:

Dim myRange As Range

Set myRange = Range("A" & CurrentRow & ":G" & CurrentRow & ",I" & CurrentRow)
myRange.Select 'this line is not really required
Selection.Locked = False
Selection.FormulaHidden = False

Set myRange = Nothing

hth,

big t

*****************************************
 
Of course, I should have mentioned that if you don't select myRange you need
to do it like this:

Dim myRange As Range

Set myRange = Range("A" & CurrentRow & ":G" & CurrentRow & ",I" & CurrentRow)
myRange.Locked = False
myRange.FormulaHidden = False

Set myRange = Nothing

cheers
big t

*************************
 
Thanks big!

My first thought when I saw your solution was...Doh! (I forget that
concatenation can be used for things like this).

Thanks for the reminder, and your help!
Bernie
 

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

Back
Top