Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default VB code to compare/validate and delete as required

Hi

Is it possible to have some code (if so what) that will compare a name from
cell C3 in sheet1 to a list of names held in sheet2 AB4:AB75
(note: it is important that the check is made from row 4 downwards for the
name match and NOT row 75 upwards!!)

If the name is found in range AB4:AB75 of sheet2 check the corresponding
column AC (sheet2) and if it DOESN'T match that of 0445-1315 then paste the
time value from the corresponding column AC into cell E3 of sheet1.
Once pasted remove the name match from column AB of sheet2

Loop this until the range of C3:C6 in sheet1 has been completed

Any ideas and thanks in advance!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VB code to compare/validate and delete as required


Dim iRow As Long
Dim rng As Range
Dim cell As Range

With Worksheets("Sheet1")
For Each cell In .Range("C3:C6")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Worksheets("Sheet2").Range("AB4:AB75"), 0)
On Error GoTo 0
If iRow < 0 Then
If Worksheets("Sheet2").Cells(iRow + 3, "AC").Value =
TimeSerial(4, 45, 0) And _
Worksheets("Sheet2").Cells(iRow + 3, "AC").Value <=
TimeSerial(13, 15, 0) Then
Worksheets("Sheet2").Cells(iRow + 3, "AC").Copy
cell.Offset(0, 2)
Worksheets("Sheet2").Cells(iRow + 3, "AB").Value = ""
End If
End If
Next cell
End With

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Anthony" wrote in message
...
Hi

Is it possible to have some code (if so what) that will compare a name

from
cell C3 in sheet1 to a list of names held in sheet2 AB4:AB75
(note: it is important that the check is made from row 4 downwards for the
name match and NOT row 75 upwards!!)

If the name is found in range AB4:AB75 of sheet2 check the corresponding
column AC (sheet2) and if it DOESN'T match that of 0445-1315 then paste

the
time value from the corresponding column AC into cell E3 of sheet1.
Once pasted remove the name match from column AB of sheet2

Loop this until the range of C3:C6 in sheet1 has been completed

Any ideas and thanks in advance!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default VB code to compare/validate and delete as required

Bob,

I have slightly adjusted ur suggested code to this..

Dim iRow As Long
Dim rng As Range
Dim cell As Range

With Sheets("sheet1")
For Each cell In .Range("C3:C6")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Sheets("sheet2").Range("AB4:AB75"), 0)
On Error GoTo 0
If iRow < 0 Then
If Sheets("sheet2").Cells(iRow + 3, "AC").Value < "4:45 -
13:15" Then
Sheets("sheet2").Cells(iRow + 3, "AC").Copy
cell.Offset(0, 2)
Sheets("sheet2").Cells(iRow + 3, "AB").Value = ""
End If
End If
Next cell
End With

and it almost works...
it copies each of the times found for the corresponding name matched, but I
want it only to copy/paste the one(s) that DON'T MATCH the time "04:45 -
13:15"
If there is a match DON'T copy/paste just leave the cell in sheet1 blank

thanks and hope this makes sense

"Bob Phillips" wrote:


Dim iRow As Long
Dim rng As Range
Dim cell As Range

With Worksheets("Sheet1")
For Each cell In .Range("C3:C6")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Worksheets("Sheet2").Range("AB4:AB75"), 0)
On Error GoTo 0
If iRow < 0 Then
If Worksheets("Sheet2").Cells(iRow + 3, "AC").Value =
TimeSerial(4, 45, 0) And _
Worksheets("Sheet2").Cells(iRow + 3, "AC").Value <=
TimeSerial(13, 15, 0) Then
Worksheets("Sheet2").Cells(iRow + 3, "AC").Copy
cell.Offset(0, 2)
Worksheets("Sheet2").Cells(iRow + 3, "AB").Value = ""
End If
End If
Next cell
End With

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Anthony" wrote in message
...
Hi

Is it possible to have some code (if so what) that will compare a name

from
cell C3 in sheet1 to a list of names held in sheet2 AB4:AB75
(note: it is important that the check is made from row 4 downwards for the
name match and NOT row 75 upwards!!)

If the name is found in range AB4:AB75 of sheet2 check the corresponding
column AC (sheet2) and if it DOESN'T match that of 0445-1315 then paste

the
time value from the corresponding column AC into cell E3 of sheet1.
Once pasted remove the name match from column AB of sheet2

Loop this until the range of C3:C6 in sheet1 has been completed

Any ideas and thanks in advance!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default VB code to compare/validate and delete as required

oops, I should have put 04:45 in the code and not 4:45
it now works !!
sorry !

"Anthony" wrote:

Bob,

I have slightly adjusted ur suggested code to this..

Dim iRow As Long
Dim rng As Range
Dim cell As Range

With Sheets("sheet1")
For Each cell In .Range("C3:C6")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Sheets("sheet2").Range("AB4:AB75"), 0)
On Error GoTo 0
If iRow < 0 Then
If Sheets("sheet2").Cells(iRow + 3, "AC").Value < "4:45 -
13:15" Then
Sheets("sheet2").Cells(iRow + 3, "AC").Copy
cell.Offset(0, 2)
Sheets("sheet2").Cells(iRow + 3, "AB").Value = ""
End If
End If
Next cell
End With

and it almost works...
it copies each of the times found for the corresponding name matched, but I
want it only to copy/paste the one(s) that DON'T MATCH the time "04:45 -
13:15"
If there is a match DON'T copy/paste just leave the cell in sheet1 blank

thanks and hope this makes sense

"Bob Phillips" wrote:


Dim iRow As Long
Dim rng As Range
Dim cell As Range

With Worksheets("Sheet1")
For Each cell In .Range("C3:C6")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Worksheets("Sheet2").Range("AB4:AB75"), 0)
On Error GoTo 0
If iRow < 0 Then
If Worksheets("Sheet2").Cells(iRow + 3, "AC").Value =
TimeSerial(4, 45, 0) And _
Worksheets("Sheet2").Cells(iRow + 3, "AC").Value <=
TimeSerial(13, 15, 0) Then
Worksheets("Sheet2").Cells(iRow + 3, "AC").Copy
cell.Offset(0, 2)
Worksheets("Sheet2").Cells(iRow + 3, "AB").Value = ""
End If
End If
Next cell
End With

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Anthony" wrote in message
...
Hi

Is it possible to have some code (if so what) that will compare a name

from
cell C3 in sheet1 to a list of names held in sheet2 AB4:AB75
(note: it is important that the check is made from row 4 downwards for the
name match and NOT row 75 upwards!!)

If the name is found in range AB4:AB75 of sheet2 check the corresponding
column AC (sheet2) and if it DOESN'T match that of 0445-1315 then paste

the
time value from the corresponding column AC into cell E3 of sheet1.
Once pasted remove the name match from column AB of sheet2

Loop this until the range of C3:C6 in sheet1 has been completed

Any ideas and thanks in advance!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VB code to compare/validate and delete as required

Oh, I thought you meant that the time had to be between 4:45 and 13:15. Lol!

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Anthony" wrote in message
...
oops, I should have put 04:45 in the code and not 4:45
it now works !!
sorry !

"Anthony" wrote:

Bob,

I have slightly adjusted ur suggested code to this..

Dim iRow As Long
Dim rng As Range
Dim cell As Range

With Sheets("sheet1")
For Each cell In .Range("C3:C6")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Sheets("sheet2").Range("AB4:AB75"), 0)
On Error GoTo 0
If iRow < 0 Then
If Sheets("sheet2").Cells(iRow + 3, "AC").Value <

"4:45 -
13:15" Then
Sheets("sheet2").Cells(iRow + 3, "AC").Copy
cell.Offset(0, 2)
Sheets("sheet2").Cells(iRow + 3, "AB").Value = ""
End If
End If
Next cell
End With

and it almost works...
it copies each of the times found for the corresponding name matched,

but I
want it only to copy/paste the one(s) that DON'T MATCH the time "04:45 -
13:15"
If there is a match DON'T copy/paste just leave the cell in sheet1 blank

thanks and hope this makes sense

"Bob Phillips" wrote:


Dim iRow As Long
Dim rng As Range
Dim cell As Range

With Worksheets("Sheet1")
For Each cell In .Range("C3:C6")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Worksheets("Sheet2").Range("AB4:AB75"), 0)
On Error GoTo 0
If iRow < 0 Then
If Worksheets("Sheet2").Cells(iRow + 3, "AC").Value =
TimeSerial(4, 45, 0) And _
Worksheets("Sheet2").Cells(iRow + 3, "AC").Value

<=
TimeSerial(13, 15, 0) Then
Worksheets("Sheet2").Cells(iRow + 3, "AC").Copy
cell.Offset(0, 2)
Worksheets("Sheet2").Cells(iRow + 3, "AB").Value =

""
End If
End If
Next cell
End With

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my

addy)

"Anthony" wrote in message
...
Hi

Is it possible to have some code (if so what) that will compare a

name
from
cell C3 in sheet1 to a list of names held in sheet2 AB4:AB75
(note: it is important that the check is made from row 4 downwards

for the
name match and NOT row 75 upwards!!)

If the name is found in range AB4:AB75 of sheet2 check the

corresponding
column AC (sheet2) and if it DOESN'T match that of 0445-1315 then

paste
the
time value from the corresponding column AC into cell E3 of sheet1.
Once pasted remove the name match from column AB of sheet2

Loop this until the range of C3:C6 in sheet1 has been completed

Any ideas and thanks in advance!






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
VB code required to compare name list Anthony Excel Programming 7 February 6th 07 01:50 PM
VB code required to compare/delete data Anthony Excel Programming 3 February 4th 07 11:39 PM
Using Vlookup to compare and validate data Big Jones Excel Worksheet Functions 1 August 19th 05 12:15 PM
validate data using code Gareth[_3_] Excel Programming 1 November 27th 03 11:37 PM
How to validate in code the contents of a cell? Heather M. Excel Programming 1 November 11th 03 08:14 AM


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