Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Non-adjacent area selection

In your logic, you confirm that the cell picked by the user is correct
and
then regardless of the answer exit the loop. You never get to the code

that sets the value for res - so it would always be zero. You never
loop.

I can't tell waht you are trying to do.

Are you trying to select from a cell designated by the user down to the
last
used row and column?

What are you trying to achieve using the Loop?

--
Regards,
Tom Ogilvy


"Petr" wrote in message
m...

Hallo,
I want to select all the cells within non-adjacent area, e.g. I want
to select the range B2:D4 when I have filled cells B2, B4 and D2,
assuming cell D4 as the last cell.


Here is my sample code:

Sub select_non_adjacent()
Dim last_col, col_num, res As Integer



Set rng1 = Cells.Find(What:="*", After:=Range("A1"),
SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
Set rng2 = Cells.Find(What:="*", After:=Range("A1"),
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)

'LastRow = Application.Max(rng1.Row, rng2.Row)
lastcol = Application.Max(rng1.Column, rng2.Column)

Do
Set rngResponse = Application.InputBox("Select initial cell",
"First cell selection", Selection.Address, , , , , 8)
If Err.Number < 0 Then Err.Clear: End
Application.Goto rngResponse
intConfirm = MsgBox("Is active cell corect?" & vbCr & vbCr &
rngResponse.Address(RowAbsolute:=False, ColumnAbsolute:=False,
External:=True), vbQuestion + vbYesNo, "Confirmation")
If intConfirm = vbYes Then
ActiveCell.Select
col_num = ActiveCell.Column


Intersect(Range(ActiveCell, _
Cells(Rows.Count, ActiveCell.Column)), _
ActiveCell.Parent.UsedRange).Select
End If
Exit Do

res = (lastcol - col_num + 1)

Selection.Resize(, res).Select

Loop


End Sub


I have got problem with res variable which always returns zero, i.e.
there is no column selection to the right. I checked via Add watch the
variables lastcol and col_num but they are correct.

Thanks a lot in advance for any suggestions.
Petr Duzbaba


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
Populate Adjacent Cells based on Pull Down Selection edvwvw via OfficeKB.com New Users to Excel 0 June 30th 09 01:28 PM
Populate Adjacent Cells based on Pull Down Selection Ambassador New Users to Excel 0 June 29th 09 12:19 AM
Excel - Sum of Values based on adjacent list selection Beki Goodwin New Users to Excel 1 April 24th 07 11:58 PM
Non-adjacent area selection rjamison Excel Programming 0 June 14th 05 12:14 AM
Non-adjacent area selection Petr Excel Programming 1 April 20th 05 03:05 PM


All times are GMT +1. The time now is 09:55 AM.

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

About Us

"It's about Microsoft Excel"