Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub GetStatus()
With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Joel,
Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub GetStatus()
With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Joel,
Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub GetStatus()
With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Joel,
I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I copied the line from the VBA help FINDNEXT not noticing the period infront
of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Okay, I changed the command line, but I still get the same run-time error
"Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Could it be because you do the 'set c' twice?!
"Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I didn't realize that FinNext didn't work with columns. I had to change the
search range to a Range object instead of a column object. Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Okay, I changed the command line, but I still get the same run-time error "Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Joel,
The code copies the same result form the first line sheet1= Customer Issue Date Phase. 123456789 30/06/2004 Pre Date 123456789 01/07/2008 Pre Date 123456789 23/12/2009 Pre Date 123456789 24/12/2009 Pre Date 123456789 25/12/2009 Pre Date 123456789 02/02/2010 Pre Date 123456789 01/01/2010 Pre Date 987654321 30/05/2008 Pre Date 987654321 01/06/2008 Pre Date 987654321 18/08/2009 Pre Date 987654321 19/08/2009 Pre Date 987654321 01/06/2010 Pre Date 987654321 01/09/2010 Pre Date sheet2 Customer Name Pre-fase Test Launch 123456789 01/01/2008 01/01/2009 01/01/2010 987654321 01/06/2008 01/06/2009 01/06/2010 As you can see regardless of value in sheet1 cel b3 and so forth the outcome is always Pre-Date "Joel" wrote: I didn't realize that FinNext didn't work with columns. I had to change the search range to a Range object instead of a column object. Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Okay, I changed the command line, but I still get the same run-time error "Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! |
#13
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
THIS WILL WORK. I had to move one line of code.
Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) End If End With If Not c Is Nothing Then IssueDate = c.Offset(0, 1) 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Could it be because you do the 'set c' twice?! "Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#14
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
looking at your data my tests weren't correct. Try this code
Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) End If End With If Not c Is Nothing Then IssueDate = c.Offset(0, 1) 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is < TestDate 'Issued Date is before Test Date c.Offset(0, 2) = "Pre Date" Case Is < ActualDate 'Issue date is greater than Test Date 'and less than Actual Date c.Offset(0, 2) = "Test Date" Case Is = ActualDate 'Issue date is greater than Actual Date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Could it be because you do the 'set c' twice?! "Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#15
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Joel,
Same situation here, still looks like the code is copying from B2 "Joel" wrote: looking at your data my tests weren't correct. Try this code Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) End If End With If Not c Is Nothing Then IssueDate = c.Offset(0, 1) 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is < TestDate 'Issued Date is before Test Date c.Offset(0, 2) = "Pre Date" Case Is < ActualDate 'Issue date is greater than Test Date 'and less than Actual Date c.Offset(0, 2) = "Test Date" Case Is = ActualDate 'Issue date is greater than Actual Date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Could it be because you do the 'set c' twice?! "Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! Many thanks in advance! Basta1980 |
#16
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I put the line below in the wrong place
IssueDate = c.Offset(0, 1) Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do IssueDate = c.Offset(0, 1) 'compare issue dates against Select Case IssueDate Case Is < TestDate 'Issued Date is before Test Date c.Offset(0, 2) = "Pre Date" Case Is < ActualDate 'Issue date is greater than Test Date 'and less than Actual Date c.Offset(0, 2) = "Test Date" Case Is = ActualDate 'Issue date is greater than Actual Date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) z = c.Address Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Joel, Same situation here, still looks like the code is copying from B2 "Joel" wrote: looking at your data my tests weren't correct. Try this code Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) End If End With If Not c Is Nothing Then IssueDate = c.Offset(0, 1) 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is < TestDate 'Issued Date is before Test Date c.Offset(0, 2) = "Pre Date" Case Is < ActualDate 'Issue date is greater than Test Date 'and less than Actual Date c.Offset(0, 2) = "Test Date" Case Is = ActualDate 'Issue date is greater than Actual Date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Could it be because you do the 'set c' twice?! "Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thank you very much. Three minor things; 1. What do I have to adjust when I use column headings?! 2. Is it also possible to switch outcome (IssueDate = c.offset(0.1) ) to an alternate place in the workbook (i.e. sheet1 as this is the main sheet)?! 3. IF you have the time; what do the first two sections mean/work?! The Case structure is claer to me, but what do the other statements do?! Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") RowCount = 1 Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) Select Case IssueDate Case Is <= PreDate .Range("E" & RowCount) = "Pre Date" Case Is <= TestDate .Range("E" & RowCount) = "Test Date" Case Is <= PreDate .Range("E" & RowCount) = "Inbetween" Case Is = ActualDate .Range("E" & RowCount) = "Actual Date" Case Else .Range("E" & RowCount) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi all, I have 2 sheets (Sheet1 and Sheet2). In sheet1 column A lists customers and column B lists Issue Dates. In sheet2 Column A lists customers, Column B a date (pre-sale), Column C a date (test date) and column D also a date (actual launch). What I want to do is lookup the customer listed in column A sheet1 in Column A sheet2, if theres a match check if the issue date in column B sheet1 is either pre-sale, test or actual launch (so check if it is smaller or larger than dates in column B:D sheet2). How do I go about?! |
#17
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The code for this will be easier to maintain - as well as be much
faster - if you use ADO instead of this row-at-a-time stuff. |
#18
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Joel,
Sorry for the somewhat delayed reaction, everything works fine. Thank u very much! Gr. Basta "Joel" wrote: I put the line below in the wrong place IssueDate = c.Offset(0, 1) Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do IssueDate = c.Offset(0, 1) 'compare issue dates against Select Case IssueDate Case Is < TestDate 'Issued Date is before Test Date c.Offset(0, 2) = "Pre Date" Case Is < ActualDate 'Issue date is greater than Test Date 'and less than Actual Date c.Offset(0, 2) = "Test Date" Case Is = ActualDate 'Issue date is greater than Actual Date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) z = c.Address Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Joel, Same situation here, still looks like the code is copying from B2 "Joel" wrote: looking at your data my tests weren't correct. Try this code Sub GetStatus() With Sheets("Sheet1") LastRow = .Range("A" & Rows.Count).End(xlUp).Row Set SearchRange = .Range("A1:A" & LastRow) End With With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = SearchRange.Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) End If End With If Not c Is Nothing Then IssueDate = c.Offset(0, 1) 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is < TestDate 'Issued Date is before Test Date c.Offset(0, 2) = "Pre Date" Case Is < ActualDate 'Issue date is greater than Test Date 'and less than Actual Date c.Offset(0, 2) = "Test Date" Case Is = ActualDate 'Issue date is greater than Actual Date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = SearchRange.FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Could it be because you do the 'set c' twice?! "Joel" wrote: I copied the line from the VBA help FINDNEXT not noticing the period infront of the FindNext. With my code it is looking on sheet 2 instead of Sheet 1 from Set c = .FindNext(after:=c) to Set c = Sheets("Sheet1").FindNext(after:=c) "Basta1980" wrote: Joel, I get a run-time erro 438 and VBA points toward Set c = .FindNext(after:=c) "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) FirstAddress = c.Address Do 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date 'and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date 'and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select Set c = .FindNext(after:=c) Loop While Not c Is Nothing And c.Address < FirstAddress End If RowCount = RowCount + 1 Loop End With End Sub "Basta1980" wrote: Hi Joel, Thanks, one more thing though. I have a list of customers which are listed more than once. With the code below I get a hit just once per customer, but I need a hit per case. So if customer Jones is listed twice with various dates it should tell me for both listings what phase it is. Regards Basta "Joel" wrote: Sub GetStatus() With Sheets("Sheet2") 'Skip Header row RowCount = 2 'look through every row of worksheet until a blank is found Do While .Range("A" & RowCount) < "" Customer = .Range("A" & RowCount) With Sheets("Sheet1") 'search column A for cutomer name in sheet 1 Set c = .Columns("A").Find(what:=Customer, _ LookIn:=xlValues, lookat:=xlWhole) If c Is Nothing Then MsgBox ("Cannot find Customer : " & Customer) Else IssueDate = c.Offset(0, 1) End If End With If Not c Is Nothing Then 'if customer is found get dates PreDate = .Range("B" & RowCount) TestDate = .Range("C" & RowCount) ActualDate = .Range("D" & RowCount) 'compare issue dates against Select Case IssueDate Case Is <= PreDate 'Issued Date is before Pre Date c.Offset(0, 2) = "Pre Date" Case Is <= TestDate 'Issue date is greater than Pre Date and less than Test Date c.Offset(0, 2) = "Test Date" Case Is <= ActualDate 'Issue date is greater than test date and less than actual date c.Offset(0, 2) = "Inbetween" Case Is = ActualDate 'Issue Date is greatter tan actual date c.Offset(0, 2) = "Actual Date" Case Else 'we should never get here c.Offset(0, 2) = "Bad Date" End Select End If RowCount = RowCount + 1 Loop End With End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Lookup Formula: Return 1st match, then 2nd match, then 3rd match | Excel Discussion (Misc queries) | |||
match one column with dates to several colums with dates, copy pas | Excel Programming | |||
Trying to match up variables to a common list and confirm | Excel Worksheet Functions | |||
Lookup? Match? pulling rows from one spreadsheet to match a text f | Excel Worksheet Functions | |||
Lookup or Match | Excel Programming |