ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   error handling message help (https://www.excelbanter.com/excel-programming/387592-error-handling-message-help.html)

Carlee

error handling message help
 
Hi there,

I have a macro which enables users to import values into a master log. Each
row inserted into the master log has a unique date.
Question:
I'd like to add some code in which Excel loops through the existing rows in
the master sheet and checks that the date to be inserted doesn't already
exist. if it does exist, display a message which enables the user to
overwrite the existing entry or cancel the import process.

Ideas?

--
Carlee

Jay

error handling message help
 
Hi Carlee -

Here's some code to test in your application. It assumes your MasterLog
data range begins in A1 and the date is in column(1). Adjust to suit.

Sub Carlee()
Const d = "5/19/07"

Set dataRng = Range("A1").CurrentRegion
If Not dataRng.Columns(1).Find(d, LookIn:=xlValues, _
lookat:=xlWhole) Is Nothing Then
If MsgBox("Date already exists in MasterLog." & Chr(13) & _
"Press OK to overwrite or CANCEL.", vbOKCancel) = vbOK Then
'Call your code to insert the record, but overwrite instead
MsgBox "Overwriting..."
Else
MsgBox "Canceled; no overwrite..."
End If
End If
End Sub
---
Jay


"Carlee" wrote:

Hi there,

I have a macro which enables users to import values into a master log. Each
row inserted into the master log has a unique date.
Question:
I'd like to add some code in which Excel loops through the existing rows in
the master sheet and checks that the date to be inserted doesn't already
exist. if it does exist, display a message which enables the user to
overwrite the existing entry or cancel the import process.

Ideas?

--
Carlee



All times are GMT +1. The time now is 02:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com