View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Lars Uffmann Lars Uffmann is offline
external usenet poster
 
Posts: 35
Default Selecting all cells in a column between two cells

Darren Ingram wrote:
I have two cells (we'll call them: Apple & Banana) in a column (for the sake
of this we'll call it column D, but it will in fact be varying columns)...
[..] What I
want to do it to put the curser on Banana (the bottom cell item) and for a
piece of code to select Banana and every cell in the column above it up to
and including Apple. I then want to process the formula that is inside of
the Apple cell (the topmost cell)so that it applies to all cells between it
and Banana and also Banana.


Dim ws As Worksheet
Dim rangeApple As Range, rangeBanana As Range

Set ws = ActiveWorksheet
' set your rangeApple and rangeBanana to those two cells here

ws.Range (ws.Cells (rangeApple.Row + 1
ws.Range(ws.Cells(rApple.Row + 1, rApple.Column), _
ws.Cells(rBanana.Row, rBanana.Column)).Formula = rApple.Formula

' done!

I know that this is a seperate question but with the apple and banana cells,
is there a piece of simple code that will work out the numerical positional
difference between the two and give me a value.


Dim rowsBetween as Long
rowsBetween = rBanana.Row - rApple.Row


HTH,

Lars