Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default On Error, Message, Exit

Hi, In the following, I need to add:
MsgBox "No #N/A cells found. Nothing to copy. Finished."
--and when clicking OK, close the workbook without saving.
before exiting in this statement: If Not IsError(.Cells(lr, "r")) Then Exit
Sub

-------------------------------------------------------------------
' copy value in columns CDE #N\A to Employees.xlsx

Set swb = ActiveWorkbook 'IF open
Set dwb = Workbooks("Employees.xlsx") 'If open
dlr = dwb.Sheets(1).Cells(Rows.Count, "a").End(xlUp).Row + 1
'MsgBox dlr
With swb.Sheets(1)
lr = .Cells(Rows.Count, "a").End(xlUp).Row

If Not IsError(.Cells(lr, "r")) Then Exit Sub

..Range("a1:r" & lr).AutoFilter field:=18, Criteria1:="#N/A"
..Range("e2:e" & lr).SpecialCells(xlCellTypeVisible).Copy
dwb.Sheets(1).Range("a" & dlr)
..Range("c2:d" & lr).SpecialCells(xlCellTypeVisible).Copy
dwb.Sheets(1).Range("b" & dlr)
..Range("a1:r" & lr).AutoFilter
nlr = dwb.Sheets(1).Cells(Rows.Count, "a").End(xlUp).Row
'MsgBox nlr

'print range
dwb.Activate
Sheets(1).PageSetup.PrintArea = Range(Cells(dlr, "a"), Cells(nlr,
"c")).Address
ActiveWindow.SelectedSheets.PrintOut
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default On Error, Message, Exit

On Mar 20, 10:21*am, Helmut wrote:
Hi, In the following, I need to add:
MsgBox "No #N/A cells found. Nothing to copy. Finished."
--and when clicking OK, close the workbook without saving.
before exiting in this statement: *If Not IsError(.Cells(lr, "r")) Then Exit
Sub

-------------------------------------------------------------------
' copy value in columns CDE #N\A to Employees.xlsx

Set swb = ActiveWorkbook 'IF open
Set dwb = Workbooks("Employees.xlsx") 'If open
dlr = dwb.Sheets(1).Cells(Rows.Count, "a").End(xlUp).Row + 1
'MsgBox dlr
With swb.Sheets(1)
lr = .Cells(Rows.Count, "a").End(xlUp).Row

*If Not IsError(.Cells(lr, "r")) Then Exit Sub

.Range("a1:r" & lr).AutoFilter field:=18, Criteria1:="#N/A"
.Range("e2:e" & lr).SpecialCells(xlCellTypeVisible).Copy
dwb.Sheets(1).Range("a" & dlr)
.Range("c2:d" & lr).SpecialCells(xlCellTypeVisible).Copy
dwb.Sheets(1).Range("b" & dlr)
.Range("a1:r" & lr).AutoFilter
nlr = dwb.Sheets(1).Cells(Rows.Count, "a").End(xlUp).Row
'MsgBox nlr

'print range
dwb.Activate
Sheets(1).PageSetup.PrintArea = Range(Cells(dlr, "a"), Cells(nlr,
"c")).Address
ActiveWindow.SelectedSheets.PrintOut
End With



This should be what you're looking for:

If Not IsError(.Cells(lr, "r")) Then
Call MsgBox("No #N/A cells found. Nothing to copy.", vbokonly,
"Finished")
Exit Sub
End If


Chris
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
replace VBA run-time error message with custom message BEEJAY Excel Programming 13 July 14th 06 03:59 PM
on error exit sub short_n_curly[_22_] Excel Programming 1 July 20th 05 07:01 PM
Exit a macro from an error condition ChuckM[_2_] Excel Programming 2 January 19th 04 02:12 PM
save on exit message box Olly[_3_] Excel Programming 3 November 7th 03 09:32 PM
save on exit message box Olly[_3_] Excel Programming 0 November 7th 03 03:37 PM


All times are GMT +1. The time now is 03:14 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"