View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Gene Augustin Gene Augustin is offline
external usenet poster
 
Posts: 36
Default Select & Move Range

At first, I got error messages. I added Dim statements for the variables and
I runs, but doesn't give correct results.
Here are the contents of A1:A12

CELL CONTENTS
B1 Data
B2 1
B3
B4 2
B5
B6
B7 3
B8 4
B9 5
B10 6
B11 7
B12 8

I select the cell below The cell containing "Data" and run the macro.

I want the macro to select the 11 cell range B2:B12 and move the selection
range to A2:A12.

The macro produces a selection of 9 cells beginning in row 4 of the adjacent
column.
It should produce the selection the 11 cell range A2:A12.

Both versions of the Range(CellsŠ line produce the same results.

I mis-stated the problem in my original request. I want the range from the
second cell in the column to the last non-blank cell in the colum.

Here's your modified code with the DIM statements added:

Sub findfirstlastcell()
Dim mc As Long
Dim fr As Long
Dim lr As Long
mc = 2 ' "d"
fr = Cells(mc, 2).End(xlDown).Row
lr = Cells(Rows.Count, mc).End(xlUp).Row
Range(Cells(fr, mc), Cells(lr, mc)).Offset(, -1).Select
'or
'Range(Cells(fr, mc-1), Cells(lr, mc-1)).Select

End Sub










On 2/15/09 10:17 AM, in article , "Don
Guillett" wrote:

One way. However, selections are seldom desirable. Post all of your code.

Sub findfirstlastcell()
mc = 4 '"d"
fr = Cells(2, mc).End(xlDown).Row
lr = Cells(Rows.Count, mc).End(xlUp).Row
Range(Cells(fr, mc), Cells(lr, mc)).Offset(, -1).Select
'or
'Range(Cells(fr, mc-1), Cells(lr, mc-1)).Select
End Sub