Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Anthony
 
Posts: n/a
Default data duplication check ?

Hi all,

I have this code which runs a macro to add a complete list of all data for
'today' to be entered into a sepeate worksheet which is called the database.
Is there a way, if so how, that the code can be changed so that if the
'same' data is entered twice a pop up message box is shown to alert the user
of this and stop this happening.

The code I have is

Sub add_Anydays_jobs()
With ActiveSheet.Range("A8:N34")
Sheets("Log").Range("A" & Rows.Count).End(xlUp).Offset( _
1, 0).Resize(.Rows.Count, .Columns.Count).Value = .Value

End With
MsgBox "All Today's Jobs Added Successfully !", vbInformation
End Sub

thanks all
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

I think you'll have to check the log sheet lots of times.

Sarting in A1(?), you'll have to check 378 cells (14 columns by 27 rows) to see
if all the values match up.

If you find a difference, drop down a row and start checking again.

If that 27 rows is an exact match, then set a flag, drop out of the loop and
issue a warning message.



Anthony wrote:

Hi all,

I have this code which runs a macro to add a complete list of all data for
'today' to be entered into a sepeate worksheet which is called the database.
Is there a way, if so how, that the code can be changed so that if the
'same' data is entered twice a pop up message box is shown to alert the user
of this and stop this happening.

The code I have is

Sub add_Anydays_jobs()
With ActiveSheet.Range("A8:N34")
Sheets("Log").Range("A" & Rows.Count).End(xlUp).Offset( _
1, 0).Resize(.Rows.Count, .Columns.Count).Value = .Value

End With
MsgBox "All Today's Jobs Added Successfully !", vbInformation
End Sub

thanks all


--

Dave Peterson
  #3   Report Post  
Anthony
 
Posts: n/a
Default

Dave
Sounds good, but sorry I'm a bit of a novice in VB, can you supply any
script to do this ?
many thanks

"Dave Peterson" wrote:

I think you'll have to check the log sheet lots of times.

Sarting in A1(?), you'll have to check 378 cells (14 columns by 27 rows) to see
if all the values match up.

If you find a difference, drop down a row and start checking again.

If that 27 rows is an exact match, then set a flag, drop out of the loop and
issue a warning message.



Anthony wrote:

Hi all,

I have this code which runs a macro to add a complete list of all data for
'today' to be entered into a sepeate worksheet which is called the database.
Is there a way, if so how, that the code can be changed so that if the
'same' data is entered twice a pop up message box is shown to alert the user
of this and stop this happening.

The code I have is

Sub add_Anydays_jobs()
With ActiveSheet.Range("A8:N34")
Sheets("Log").Range("A" & Rows.Count).End(xlUp).Offset( _
1, 0).Resize(.Rows.Count, .Columns.Count).Value = .Value

End With
MsgBox "All Today's Jobs Added Successfully !", vbInformation
End Sub

thanks all


--

Dave Peterson

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Ouch. I was afraid of that followup!

This worked for me under minor testing...

Option Explicit
Sub add_Anydays_jobs2()

Dim DataWks As Worksheet
Dim LogWks As Worksheet
Dim FoundACellDiff As Boolean
Dim FoundAGroupMatch As Boolean
Dim RngToCopy As Range
Dim testRng As Range

Dim iRow As Long
Dim FirstRowToCheck As Long
Dim LastRowToCheck As Long

Dim cCol As Long
Dim cRow As Long

Dim DestCell As Range

Set DataWks = Worksheets("sheet1")
Set LogWks = Worksheets("Log")

Set RngToCopy = DataWks.Range("a8:n34")

With LogWks
FirstRowToCheck = 2 'headers?
LastRowToCheck = .Cells(.Rows.Count, "A").End(xlUp).Row

FoundAGroupMatch = False
For iRow = FirstRowToCheck To LastRowToCheck
'topleftcell of possible range to paste
Set testRng = .Cells(iRow, "A")
FoundACellDiff = False
For cRow = 1 To RngToCopy.Rows.Count
For cCol = 1 To RngToCopy.Columns.Count
If RngToCopy.Cells(cRow, cCol).Value _
= testRng.Cells(cRow, cCol).Value Then
'still the same
'so do nothing
Else
FoundACellDiff = True
Exit For
End If
Next cCol
If FoundACellDiff Then
Exit For
End If
Next cRow
If FoundACellDiff = False Then
FoundAGroupMatch = True
Exit For
End If
Next iRow


If FoundAGroupMatch = True Then
MsgBox "Those values already exist!"
'exit sub '????
Else
MsgBox "Hey, they look unique"
'do the copy?
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
DestCell.Resize(RngToCopy.Rows.Count, _
RngToCopy.Columns.Count).Value _
= RngToCopy.Value
End If
End With
End Sub

Anthony wrote:

Dave
Sounds good, but sorry I'm a bit of a novice in VB, can you supply any
script to do this ?
many thanks

"Dave Peterson" wrote:

I think you'll have to check the log sheet lots of times.

Sarting in A1(?), you'll have to check 378 cells (14 columns by 27 rows) to see
if all the values match up.

If you find a difference, drop down a row and start checking again.

If that 27 rows is an exact match, then set a flag, drop out of the loop and
issue a warning message.



Anthony wrote:

Hi all,

I have this code which runs a macro to add a complete list of all data for
'today' to be entered into a sepeate worksheet which is called the database.
Is there a way, if so how, that the code can be changed so that if the
'same' data is entered twice a pop up message box is shown to alert the user
of this and stop this happening.

The code I have is

Sub add_Anydays_jobs()
With ActiveSheet.Range("A8:N34")
Sheets("Log").Range("A" & Rows.Count).End(xlUp).Offset( _
1, 0).Resize(.Rows.Count, .Columns.Count).Value = .Value

End With
MsgBox "All Today's Jobs Added Successfully !", vbInformation
End Sub

thanks all


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Anthony
 
Posts: n/a
Default

Dave,
whan I have a spare minute (kids!) I'll give ur code a try, but hey, many
thanks for the stuff posted here, I'll let you know how I get on
many thanks
Anthony

"Dave Peterson" wrote:

Ouch. I was afraid of that followup!

This worked for me under minor testing...

Option Explicit
Sub add_Anydays_jobs2()

Dim DataWks As Worksheet
Dim LogWks As Worksheet
Dim FoundACellDiff As Boolean
Dim FoundAGroupMatch As Boolean
Dim RngToCopy As Range
Dim testRng As Range

Dim iRow As Long
Dim FirstRowToCheck As Long
Dim LastRowToCheck As Long

Dim cCol As Long
Dim cRow As Long

Dim DestCell As Range

Set DataWks = Worksheets("sheet1")
Set LogWks = Worksheets("Log")

Set RngToCopy = DataWks.Range("a8:n34")

With LogWks
FirstRowToCheck = 2 'headers?
LastRowToCheck = .Cells(.Rows.Count, "A").End(xlUp).Row

FoundAGroupMatch = False
For iRow = FirstRowToCheck To LastRowToCheck
'topleftcell of possible range to paste
Set testRng = .Cells(iRow, "A")
FoundACellDiff = False
For cRow = 1 To RngToCopy.Rows.Count
For cCol = 1 To RngToCopy.Columns.Count
If RngToCopy.Cells(cRow, cCol).Value _
= testRng.Cells(cRow, cCol).Value Then
'still the same
'so do nothing
Else
FoundACellDiff = True
Exit For
End If
Next cCol
If FoundACellDiff Then
Exit For
End If
Next cRow
If FoundACellDiff = False Then
FoundAGroupMatch = True
Exit For
End If
Next iRow


If FoundAGroupMatch = True Then
MsgBox "Those values already exist!"
'exit sub '????
Else
MsgBox "Hey, they look unique"
'do the copy?
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
DestCell.Resize(RngToCopy.Rows.Count, _
RngToCopy.Columns.Count).Value _
= RngToCopy.Value
End If
End With
End Sub

Anthony wrote:

Dave
Sounds good, but sorry I'm a bit of a novice in VB, can you supply any
script to do this ?
many thanks

"Dave Peterson" wrote:

I think you'll have to check the log sheet lots of times.

Sarting in A1(?), you'll have to check 378 cells (14 columns by 27 rows) to see
if all the values match up.

If you find a difference, drop down a row and start checking again.

If that 27 rows is an exact match, then set a flag, drop out of the loop and
issue a warning message.



Anthony wrote:

Hi all,

I have this code which runs a macro to add a complete list of all data for
'today' to be entered into a sepeate worksheet which is called the database.
Is there a way, if so how, that the code can be changed so that if the
'same' data is entered twice a pop up message box is shown to alert the user
of this and stop this happening.

The code I have is

Sub add_Anydays_jobs()
With ActiveSheet.Range("A8:N34")
Sheets("Log").Range("A" & Rows.Count).End(xlUp).Offset( _
1, 0).Resize(.Rows.Count, .Columns.Count).Value = .Value

End With
MsgBox "All Today's Jobs Added Successfully !", vbInformation
End Sub

thanks all

--

Dave Peterson


--

Dave Peterson

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
Why is the order of my data table opposite from graph? mozermodo Charts and Charting in Excel 6 April 25th 23 03:43 AM
Data Source Name Not Found Justin Tyme Excel Worksheet Functions 0 June 16th 05 11:45 PM
Help making a chart that doesn't graph cells without data? Filtration Guy Excel Discussion (Misc queries) 0 March 22nd 05 09:21 PM
Adding more source data to existing scatter plot Tom Charts and Charting in Excel 1 March 21st 05 10:03 PM
Need formula to check values of data in several cells as criteria VCTECH Excel Worksheet Functions 0 November 19th 04 09:54 PM


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