Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why my selection is lost with MsgBox?

I have a rows selection to delete, and using a msgbox I want to ask user to
do ok or cancel, but when the msgbox is popup, my rows selection is lost :o(
How could I avoid that problem? Thank you!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Why my selection is lost with MsgBox?

Get a reference to the selection before you pop up the messagebox.

dim rngSel as range
set rngSel = selection
'do stuff which might change selection
'operate on rngSel

However, msgbox doesn't change the selection for me, so maybe you're
doing something else in your code?

Tim

"MLevesque" wrote in message
...
I have a rows selection to delete, and using a msgbox I want to ask
user to
do ok or cancel, but when the msgbox is popup, my rows selection is
lost :o(
How could I avoid that problem? Thank you!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Why my selection is lost with MsgBox?

I agree. Below is my experiment. It stays highlighted until I send the right
cursor keystroke whether I delete the row or not. Watch that you are not
unintentionally releasing the selection somehow.

Roy

Dim x As Integer
Rows(7).Select
x = MsgBox("Really delete this row? Press OK to delete or Cancel to abort.",
vbOKCancel + vbExclamation, "Delete Row?")
If x = vbOK Then
Rows(7).Delete
End If
SendKeys "{RIGHT}" 'to relase the selection




--
(delete .nospam)




"Tim Williams" wrote:

Get a reference to the selection before you pop up the messagebox.

dim rngSel as range
set rngSel = selection
'do stuff which might change selection
'operate on rngSel

However, msgbox doesn't change the selection for me, so maybe you're
doing something else in your code?

Tim

"MLevesque" wrote in message
...
I have a rows selection to delete, and using a msgbox I want to ask
user to
do ok or cancel, but when the msgbox is popup, my rows selection is
lost :o(
How could I avoid that problem? Thank you!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why my selection is lost with MsgBox?

Thank you, but it does not work for me. My code is the following...
if msgbox("Do you really want to delete selected rows?"...) = vbOk then
for each rng in selection
if rng.row = 10 and rng.row <= 20 then
rng.entirerow.delete
endif
next rng
endif

"Tim Williams" wrote:

Get a reference to the selection before you pop up the messagebox.

dim rngSel as range
set rngSel = selection
'do stuff which might change selection
'operate on rngSel

However, msgbox doesn't change the selection for me, so maybe you're
doing something else in your code?

Tim

"MLevesque" wrote in message
...
I have a rows selection to delete, and using a msgbox I want to ask
user to
do ok or cancel, but when the msgbox is popup, my rows selection is
lost :o(
How could I avoid that problem? Thank you!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Why my selection is lost with MsgBox?

Try this:

dim x
if msgbox("Do you really want to delete selected rows?"...) = vbOk
then
Selection.EntireRow.Delete
end if

Problem with your approach is you can't delete rows without affecting
the selection - that causes problems with your loop.

Tim.


"MLevesque" wrote in message
...
Thank you, but it does not work for me. My code is the following...
if msgbox("Do you really want to delete selected rows?"...) = vbOk
then
for each rng in selection
if rng.row = 10 and rng.row <= 20 then
rng.entirerow.delete
endif
next rng
endif

"Tim Williams" wrote:

Get a reference to the selection before you pop up the messagebox.

dim rngSel as range
set rngSel = selection
'do stuff which might change selection
'operate on rngSel

However, msgbox doesn't change the selection for me, so maybe
you're
doing something else in your code?

Tim

"MLevesque" wrote in message
...
I have a rows selection to delete, and using a msgbox I want to
ask
user to
do ok or cancel, but when the msgbox is popup, my rows selection
is
lost :o(
How could I avoid that problem? Thank you!








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why my selection is lost with MsgBox?

I know but I need to verify each row before deletion. I cannot do only a
Selection.EntireRow.Delete


"Tim Williams" wrote:

Try this:

dim x
if msgbox("Do you really want to delete selected rows?"...) = vbOk
then
Selection.EntireRow.Delete
end if

Problem with your approach is you can't delete rows without affecting
the selection - that causes problems with your loop.

Tim.


"MLevesque" wrote in message
...
Thank you, but it does not work for me. My code is the following...
if msgbox("Do you really want to delete selected rows?"...) = vbOk
then
for each rng in selection
if rng.row = 10 and rng.row <= 20 then
rng.entirerow.delete
endif
next rng
endif

"Tim Williams" wrote:

Get a reference to the selection before you pop up the messagebox.

dim rngSel as range
set rngSel = selection
'do stuff which might change selection
'operate on rngSel

However, msgbox doesn't change the selection for me, so maybe
you're
doing something else in your code?

Tim

"MLevesque" wrote in message
...
I have a rows selection to delete, and using a msgbox I want to
ask
user to
do ok or cancel, but when the msgbox is popup, my rows selection
is
lost :o(
How could I avoid that problem? Thank you!






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why my selection is lost with MsgBox?

Everything is ok now. Sorry I did a mistake!
Thank you!!

"Tim Williams" wrote:

Get a reference to the selection before you pop up the messagebox.

dim rngSel as range
set rngSel = selection
'do stuff which might change selection
'operate on rngSel

However, msgbox doesn't change the selection for me, so maybe you're
doing something else in your code?

Tim

"MLevesque" wrote in message
...
I have a rows selection to delete, and using a msgbox I want to ask
user to
do ok or cancel, but when the msgbox is popup, my rows selection is
lost :o(
How could I avoid that problem? Thank you!




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
Returning a cell address in a msgbox, by selection via inputbox Ty FARAZ QURESHI Excel Discussion (Misc queries) 3 April 8th 09 12:57 PM
selection and visibility, lost charts Rene Charts and Charting in Excel 0 January 19th 09 11:40 PM
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM
How do I keep a running total of pounds lost and percentage lost angel5959 Excel Discussion (Misc queries) 4 January 26th 06 09:18 PM
how change selection when msgbox dialog box on screen? Ian Elliott[_2_] Excel Programming 1 September 9th 03 01:47 PM


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

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

About Us

"It's about Microsoft Excel"