How to determine which rows contain slected cells in a multiple c.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I've selected a number of different cells in a column , I would like to
set a certain value in the corresponding neigbouring cells by pressing a
button.
So I have to access the slected row values somehow. So far it only works
when a continuous set of cells is selected, using the selection.rows.count
propertie.
Who can help me?
 
I'm not quite sure what you're doing, but maybe you can loop through the
discontiguous areas:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myArea As Range

Set myRng = Selection
For Each myArea In myRng.Areas
myArea.Offset(0, 1).Value = "Hi there"
Next myArea
End Sub
 
Hi Dave,

Thanks very much for your help.
I missed your reply, but fortunately found it today.
It was essentially what I was looking for.
To be precize I wanted to do the following:

Sub testme()
Dim myRng As Range
Dim myArea As Range

Set myRng = Selection
For Each myArea In myRng.Areas
x = myArea.Row
y = myArea.Count
Range("N" & x & ":N" & x + y - 1).Value = "Hi there"
Next myArea

End Sub

Thanks again!

Paul Westerman
 

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