Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default vbOKCancel Problem

Hi, could someone please help me with the following code: when I click
on the OK button the code simply exits the subroutine. What I need is
for the user to click on the cancel button and then the subroutine
exits. However, if the user clicks on the OK buton, I need the
subroutine to continue to the end.

Any help would be greatly appreciated.

Kind regards,

Chris.

Sub copylastrowtocolVdown()

Dim lr As Long

Application.ScreenUpdating = False

MsgBox "Copy Last Record Down when the last Position Data record has
been populated in readiness to be copied into the last blank row
below.", vbOKCancel, "Copy Last Record Down"

If vbCancel Then Exit Sub

lr = Cells(Rows.Count, "a").End(xlUp).Row
Cells(lr, 1).Resize(, 22).Copy Cells(lr, 1).Resize(2)

Application.ScreenUpdating = True

End Sub



*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default vbOKCancel Problem

Msgbox is a function and you can use it like any other Excel function.
Screenupdating should be on while the msgbox is displayed...
'--
Sub copylastrowtocolVdown()
Dim lr As Long
lr = MsgBox("Copy Last Record down after the last record is entered. ", _
vbOKCancel, "Copy Last Record Down")
If lr = vbCancel Then Exit Sub

Application.ScreenUpdating = False
lr = Cells(Rows.Count, "a").End(xlUp).Row
Cells(lr, 1).Resize(, 22).Copy Cells(lr, 1).Resize(2)
Application.ScreenUpdating = True
End Sub
--
Jim Cone
Portland, Oregon USA


"Chris"
wrote in message
Hi, could someone please help me with the following code: when I click
on the OK button the code simply exits the subroutine. What I need is
for the user to click on the cancel button and then the subroutine
exits. However, if the user clicks on the OK buton, I need the
subroutine to continue to the end.

Any help would be greatly appreciated.

Kind regards,

Chris.

Sub copylastrowtocolVdown()

Dim lr As Long

Application.ScreenUpdating = False

MsgBox "Copy Last Record Down when the last Position Data record has
been populated in readiness to be copied into the last blank row
below.", vbOKCancel, "Copy Last Record Down"

If vbCancel Then Exit Sub

lr = Cells(Rows.Count, "a").End(xlUp).Row
Cells(lr, 1).Resize(, 22).Copy Cells(lr, 1).Resize(2)

Application.ScreenUpdating = True

End Sub



*** Sent via Developersdex http://www.developersdex.com ***
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default vbOKCancel Problem

Resp = MsgBox("Copy Last Record Down when the last" _
"Position Data record has been populated in" _
"readiness to be copied into the last blank" _
"row below.", vbOKCancel, "Copy Last Record Down")

If Resp = vbCancel Then Exit Sub




"Chris" wrote in message
...
Hi, could someone please help me with the following code: when I click
on the OK button the code simply exits the subroutine. What I need is
for the user to click on the cancel button and then the subroutine
exits. However, if the user clicks on the OK buton, I need the
subroutine to continue to the end.

Any help would be greatly appreciated.

Kind regards,

Chris.

Sub copylastrowtocolVdown()

Dim lr As Long

Application.ScreenUpdating = False

MsgBox "Copy Last Record Down when the last Position Data record has
been populated in readiness to be copied into the last blank row
below.", vbOKCancel, "Copy Last Record Down"

If vbCancel Then Exit Sub

lr = Cells(Rows.Count, "a").End(xlUp).Row
Cells(lr, 1).Resize(, 22).Copy Cells(lr, 1).Resize(2)

Application.ScreenUpdating = True

End Sub



*** Sent via Developersdex http://www.developersdex.com ***



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default vbOKCancel Problem

Thanks Jim for your help - your code works great - much appreciated.

Cheers,

Chris.



*** Sent via Developersdex http://www.developersdex.com ***
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default vbOKCancel Problem

Thanks JLGWhiz for your help - greatly appreciated.

Cheers,

Chris.



*** Sent via Developersdex http://www.developersdex.com ***


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default vbOKCancel Problem

Sub copylastrowtocolVdown()

Dim lr As Long

Application.ScreenUpdating = False

IF MsgBox("Copy Last Record Down when the last Position Data record has been
populated in readiness to be copied into the last blank rowbelow." _
, vbOKCancel, "Copy Last Record Down" ) = vbCancel THEN
Exit Sub
End If
lr = Cells(Rows.Count, "a").End(xlUp).Row
Cells(lr, 1).Resize(, 22).Copy Cells(lr, 1).Resize(2)

Application.ScreenUpdating = True

End Sub



"Chris" wrote in message
...
Hi, could someone please help me with the following code: when I click
on the OK button the code simply exits the subroutine. What I need is
for the user to click on the cancel button and then the subroutine
exits. However, if the user clicks on the OK buton, I need the
subroutine to continue to the end.

Any help would be greatly appreciated.

Kind regards,

Chris.

Sub copylastrowtocolVdown()

Dim lr As Long

Application.ScreenUpdating = False

MsgBox "Copy Last Record Down when the last Position Data record has
been populated in readiness to be copied into the last blank row
below.", vbOKCancel, "Copy Last Record Down"

If vbCancel Then Exit Sub

lr = Cells(Rows.Count, "a").End(xlUp).Row
Cells(lr, 1).Resize(, 22).Copy Cells(lr, 1).Resize(2)

Application.ScreenUpdating = True

End Sub



*** Sent via Developersdex http://www.developersdex.com ***


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default vbOKCancel Problem

Thanks Patrick for your help - much appreciated,

Kind regards,

Chris.



*** Sent via Developersdex http://www.developersdex.com ***
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
How to Override a VBOKCancel button? Venkatesh V Excel Programming 2 May 6th 09 01:55 AM
changing vbOKCancel button title Jase Excel Discussion (Misc queries) 8 August 19th 08 08:56 PM
Exiting Sub when Selecting Cancel on vbOKCancel Rob Excel Discussion (Misc queries) 6 June 1st 07 03:46 AM
vbOKCancel box to close [email protected] Excel Programming 3 August 22nd 06 10:02 AM
Qn: vbOKCancel -- Cancel doesn't work?? Michael Vaughan Excel Programming 4 August 27th 04 07:31 PM


All times are GMT +1. The time now is 08:29 PM.

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"