Compare Value in Cell to Array and then Add Value if True











up vote
1
down vote

favorite












I'm still a bit new to VBA and have been working on making my own macros and all on & off. But I have a bit of an issue with a bit of code.



I have a log that I record vendor information in to, and on the worksheet, I have this code below that searches for value entered on it via number entry and it then checks to see if a name is affiliated to it from another worksheet containing the table of names.



The code below works fine for the most part, however, I have had a difficult time trying to get it to also search if the value entered has already been entered either above or below it. As it stands, when a number is entered, it pulls the name and then adds a value of 1 to a corresponding cell by the found result on the worksheet containing the list of names.



The end result I am trying to achieve, is to have it check if the name exists on the current worksheet (Not the sheet with the list of names), and if it does, will not add a value of 1 to the sheet containing all of my names and numbers.



I've tried using a loop but have had no success in getting it to work. Any help would be greatly appreciated!



If Target.Count > 1 Then Exit Sub

If Not Intersect(Target, Range("B6:B37", "B46:B77")) Is Nothing Then

If WorksheetFunction.IsNumber(Target.Value) Then

Application.EnableEvents = False

Vendor = Sheet8.Range("A2:B500")
Target.Value = Application.VLookup(Target.Value, Vendor, 2, False)

Application.EnableEvents = True

Set StartValue = ThisWorkbook.Sheets("Vendor List").Range("A:B").Find(What:=Target.Value, LookIn:=xlValues)
cPos = StartValue.Address

Set ThisValue = ThisWorkbook.Sheets("Wednesday").Range("B6:B77").Find(What:=Target.Value, _
After:=Target.Value, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchDirection:=xlNext, _
MatchCase:=True, _
SearchFormat:=False)

ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value + 1

End If

If IsError(Target.Value) Then

Target.Value = ""
MsgBox "The Vendor number entered is not listed. Either you have entered an invalid number, or you have not yet added this vendor to the Vendor List sheet.", vbCritical
ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value - 1

End If

End If


I've attached an image of how it works. Hopefully, it clears a bit up...



Example










share|improve this question
























  • Is this a handler in a worksheet, or in the ThisWorkbook module?
    – Tim Williams
    Nov 14 at 23:10










  • It's a handler within a worksheet.
    – T. Francois
    Nov 14 at 23:18










  • Are you saying that you want a 1 in the Frequency column the first time a vendor is used on the Wednesday sheet? And then you don't want that 1 to ever increase no matter how many times that vendor is used? If so, then ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = 1 will do it.
    – Dick Kusleika
    Nov 14 at 23:42










  • Basically, I have a log for everyday of the week. And the purpose of having a column to record frequency, is to track delivery frequency per day and not necessarily how many times an entry is recorded by the same vendor per day. So if a vendor delivers 5 times in a week, it will show 5. There's more in the backend of my log, but am ultimately attempting to create a pivottable with the info in the end.
    – T. Francois
    Nov 14 at 23:47

















up vote
1
down vote

favorite












I'm still a bit new to VBA and have been working on making my own macros and all on & off. But I have a bit of an issue with a bit of code.



I have a log that I record vendor information in to, and on the worksheet, I have this code below that searches for value entered on it via number entry and it then checks to see if a name is affiliated to it from another worksheet containing the table of names.



The code below works fine for the most part, however, I have had a difficult time trying to get it to also search if the value entered has already been entered either above or below it. As it stands, when a number is entered, it pulls the name and then adds a value of 1 to a corresponding cell by the found result on the worksheet containing the list of names.



The end result I am trying to achieve, is to have it check if the name exists on the current worksheet (Not the sheet with the list of names), and if it does, will not add a value of 1 to the sheet containing all of my names and numbers.



I've tried using a loop but have had no success in getting it to work. Any help would be greatly appreciated!



If Target.Count > 1 Then Exit Sub

If Not Intersect(Target, Range("B6:B37", "B46:B77")) Is Nothing Then

If WorksheetFunction.IsNumber(Target.Value) Then

Application.EnableEvents = False

Vendor = Sheet8.Range("A2:B500")
Target.Value = Application.VLookup(Target.Value, Vendor, 2, False)

Application.EnableEvents = True

Set StartValue = ThisWorkbook.Sheets("Vendor List").Range("A:B").Find(What:=Target.Value, LookIn:=xlValues)
cPos = StartValue.Address

Set ThisValue = ThisWorkbook.Sheets("Wednesday").Range("B6:B77").Find(What:=Target.Value, _
After:=Target.Value, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchDirection:=xlNext, _
MatchCase:=True, _
SearchFormat:=False)

ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value + 1

End If

If IsError(Target.Value) Then

Target.Value = ""
MsgBox "The Vendor number entered is not listed. Either you have entered an invalid number, or you have not yet added this vendor to the Vendor List sheet.", vbCritical
ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value - 1

End If

End If


I've attached an image of how it works. Hopefully, it clears a bit up...



Example










share|improve this question
























  • Is this a handler in a worksheet, or in the ThisWorkbook module?
    – Tim Williams
    Nov 14 at 23:10










  • It's a handler within a worksheet.
    – T. Francois
    Nov 14 at 23:18










  • Are you saying that you want a 1 in the Frequency column the first time a vendor is used on the Wednesday sheet? And then you don't want that 1 to ever increase no matter how many times that vendor is used? If so, then ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = 1 will do it.
    – Dick Kusleika
    Nov 14 at 23:42










  • Basically, I have a log for everyday of the week. And the purpose of having a column to record frequency, is to track delivery frequency per day and not necessarily how many times an entry is recorded by the same vendor per day. So if a vendor delivers 5 times in a week, it will show 5. There's more in the backend of my log, but am ultimately attempting to create a pivottable with the info in the end.
    – T. Francois
    Nov 14 at 23:47















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm still a bit new to VBA and have been working on making my own macros and all on & off. But I have a bit of an issue with a bit of code.



I have a log that I record vendor information in to, and on the worksheet, I have this code below that searches for value entered on it via number entry and it then checks to see if a name is affiliated to it from another worksheet containing the table of names.



The code below works fine for the most part, however, I have had a difficult time trying to get it to also search if the value entered has already been entered either above or below it. As it stands, when a number is entered, it pulls the name and then adds a value of 1 to a corresponding cell by the found result on the worksheet containing the list of names.



The end result I am trying to achieve, is to have it check if the name exists on the current worksheet (Not the sheet with the list of names), and if it does, will not add a value of 1 to the sheet containing all of my names and numbers.



I've tried using a loop but have had no success in getting it to work. Any help would be greatly appreciated!



If Target.Count > 1 Then Exit Sub

If Not Intersect(Target, Range("B6:B37", "B46:B77")) Is Nothing Then

If WorksheetFunction.IsNumber(Target.Value) Then

Application.EnableEvents = False

Vendor = Sheet8.Range("A2:B500")
Target.Value = Application.VLookup(Target.Value, Vendor, 2, False)

Application.EnableEvents = True

Set StartValue = ThisWorkbook.Sheets("Vendor List").Range("A:B").Find(What:=Target.Value, LookIn:=xlValues)
cPos = StartValue.Address

Set ThisValue = ThisWorkbook.Sheets("Wednesday").Range("B6:B77").Find(What:=Target.Value, _
After:=Target.Value, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchDirection:=xlNext, _
MatchCase:=True, _
SearchFormat:=False)

ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value + 1

End If

If IsError(Target.Value) Then

Target.Value = ""
MsgBox "The Vendor number entered is not listed. Either you have entered an invalid number, or you have not yet added this vendor to the Vendor List sheet.", vbCritical
ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value - 1

End If

End If


I've attached an image of how it works. Hopefully, it clears a bit up...



Example










share|improve this question















I'm still a bit new to VBA and have been working on making my own macros and all on & off. But I have a bit of an issue with a bit of code.



I have a log that I record vendor information in to, and on the worksheet, I have this code below that searches for value entered on it via number entry and it then checks to see if a name is affiliated to it from another worksheet containing the table of names.



The code below works fine for the most part, however, I have had a difficult time trying to get it to also search if the value entered has already been entered either above or below it. As it stands, when a number is entered, it pulls the name and then adds a value of 1 to a corresponding cell by the found result on the worksheet containing the list of names.



The end result I am trying to achieve, is to have it check if the name exists on the current worksheet (Not the sheet with the list of names), and if it does, will not add a value of 1 to the sheet containing all of my names and numbers.



I've tried using a loop but have had no success in getting it to work. Any help would be greatly appreciated!



If Target.Count > 1 Then Exit Sub

If Not Intersect(Target, Range("B6:B37", "B46:B77")) Is Nothing Then

If WorksheetFunction.IsNumber(Target.Value) Then

Application.EnableEvents = False

Vendor = Sheet8.Range("A2:B500")
Target.Value = Application.VLookup(Target.Value, Vendor, 2, False)

Application.EnableEvents = True

Set StartValue = ThisWorkbook.Sheets("Vendor List").Range("A:B").Find(What:=Target.Value, LookIn:=xlValues)
cPos = StartValue.Address

Set ThisValue = ThisWorkbook.Sheets("Wednesday").Range("B6:B77").Find(What:=Target.Value, _
After:=Target.Value, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchDirection:=xlNext, _
MatchCase:=True, _
SearchFormat:=False)

ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value + 1

End If

If IsError(Target.Value) Then

Target.Value = ""
MsgBox "The Vendor number entered is not listed. Either you have entered an invalid number, or you have not yet added this vendor to the Vendor List sheet.", vbCritical
ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value - 1

End If

End If


I've attached an image of how it works. Hopefully, it clears a bit up...



Example







excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 23:05

























asked Nov 14 at 22:53









T. Francois

103




103












  • Is this a handler in a worksheet, or in the ThisWorkbook module?
    – Tim Williams
    Nov 14 at 23:10










  • It's a handler within a worksheet.
    – T. Francois
    Nov 14 at 23:18










  • Are you saying that you want a 1 in the Frequency column the first time a vendor is used on the Wednesday sheet? And then you don't want that 1 to ever increase no matter how many times that vendor is used? If so, then ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = 1 will do it.
    – Dick Kusleika
    Nov 14 at 23:42










  • Basically, I have a log for everyday of the week. And the purpose of having a column to record frequency, is to track delivery frequency per day and not necessarily how many times an entry is recorded by the same vendor per day. So if a vendor delivers 5 times in a week, it will show 5. There's more in the backend of my log, but am ultimately attempting to create a pivottable with the info in the end.
    – T. Francois
    Nov 14 at 23:47




















  • Is this a handler in a worksheet, or in the ThisWorkbook module?
    – Tim Williams
    Nov 14 at 23:10










  • It's a handler within a worksheet.
    – T. Francois
    Nov 14 at 23:18










  • Are you saying that you want a 1 in the Frequency column the first time a vendor is used on the Wednesday sheet? And then you don't want that 1 to ever increase no matter how many times that vendor is used? If so, then ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = 1 will do it.
    – Dick Kusleika
    Nov 14 at 23:42










  • Basically, I have a log for everyday of the week. And the purpose of having a column to record frequency, is to track delivery frequency per day and not necessarily how many times an entry is recorded by the same vendor per day. So if a vendor delivers 5 times in a week, it will show 5. There's more in the backend of my log, but am ultimately attempting to create a pivottable with the info in the end.
    – T. Francois
    Nov 14 at 23:47


















Is this a handler in a worksheet, or in the ThisWorkbook module?
– Tim Williams
Nov 14 at 23:10




Is this a handler in a worksheet, or in the ThisWorkbook module?
– Tim Williams
Nov 14 at 23:10












It's a handler within a worksheet.
– T. Francois
Nov 14 at 23:18




It's a handler within a worksheet.
– T. Francois
Nov 14 at 23:18












Are you saying that you want a 1 in the Frequency column the first time a vendor is used on the Wednesday sheet? And then you don't want that 1 to ever increase no matter how many times that vendor is used? If so, then ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = 1 will do it.
– Dick Kusleika
Nov 14 at 23:42




Are you saying that you want a 1 in the Frequency column the first time a vendor is used on the Wednesday sheet? And then you don't want that 1 to ever increase no matter how many times that vendor is used? If so, then ThisWorkbook.Sheets("Vendor List").Range(cPos).Offset(0, 8).Value = 1 will do it.
– Dick Kusleika
Nov 14 at 23:42












Basically, I have a log for everyday of the week. And the purpose of having a column to record frequency, is to track delivery frequency per day and not necessarily how many times an entry is recorded by the same vendor per day. So if a vendor delivers 5 times in a week, it will show 5. There's more in the backend of my log, but am ultimately attempting to create a pivottable with the info in the end.
– T. Francois
Nov 14 at 23:47






Basically, I have a log for everyday of the week. And the purpose of having a column to record frequency, is to track delivery frequency per day and not necessarily how many times an entry is recorded by the same vendor per day. So if a vendor delivers 5 times in a week, it will show 5. There's more in the backend of my log, but am ultimately attempting to create a pivottable with the info in the end.
– T. Francois
Nov 14 at 23:47














1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Untested:



Private Sub Worksheet_Change(ByVal Target As Range)
Const RNG_VENDOR As String = "B6:B37,B46:B77"

Dim v, f As Range, vendor, vendorCount

If Target.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(RNG_VENDOR)) Is Nothing Then Exit Sub

v = Target.Value
If IsNumeric(v) And Len(v) > 0 Then

'see if there's a numeric match
Set f = Sheet8.Range("A:A").Find(v, lookat:=xlWhole, LookIn:=xlValues)
If Not f Is Nothing Then
vendor = f.EntireRow.Cells(1, "B").Value 'get the vendor name
'#### edit below to fix lookup range
vendorCount = Application.CountIf(Me.Range("B6:B77"), vendor) 'count any existing
'update the vendors sheet?
With f.EntireRow.Cells(1, "J")
If vendorCount = 0 Then .Value = .Value + 1
End With
Application.EnableEvents = False
Target.Value = vendor 'switch from vendor number to vendor name
Application.EnableEvents = True

Else
Application.EnableEvents = False
Target.Value = "" 'clear the value
Application.EnableEvents = True
MsgBox "The Vendor number '" & v & "' entered is not listed....", vbExclamation
End If 'was found
End If 'is a number

End Sub





share|improve this answer























  • Works flawlessly! Thank you for your assistance. However, when recording an additional entry with the same name, it still increases the value by 1 regardless if there's multiple instances of a name.
    – T. Francois
    Nov 14 at 23:40












  • If you use MsgBox vendorCount in that situation what value pops up?
    – Tim Williams
    Nov 14 at 23:57










  • Nothing happens. No message box comes up.
    – T. Francois
    Nov 15 at 0:11










  • Well something should pop up if you put that Msgbox right after vendorCount = ...
    – Tim Williams
    Nov 15 at 0:20










  • Nothing does unfortunately. I'll have to take a stab at it tomorrow, as my brain is fried from messing around with everything earlier.
    – T. Francois
    Nov 15 at 0:37











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309936%2fcompare-value-in-cell-to-array-and-then-add-value-if-true%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










Untested:



Private Sub Worksheet_Change(ByVal Target As Range)
Const RNG_VENDOR As String = "B6:B37,B46:B77"

Dim v, f As Range, vendor, vendorCount

If Target.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(RNG_VENDOR)) Is Nothing Then Exit Sub

v = Target.Value
If IsNumeric(v) And Len(v) > 0 Then

'see if there's a numeric match
Set f = Sheet8.Range("A:A").Find(v, lookat:=xlWhole, LookIn:=xlValues)
If Not f Is Nothing Then
vendor = f.EntireRow.Cells(1, "B").Value 'get the vendor name
'#### edit below to fix lookup range
vendorCount = Application.CountIf(Me.Range("B6:B77"), vendor) 'count any existing
'update the vendors sheet?
With f.EntireRow.Cells(1, "J")
If vendorCount = 0 Then .Value = .Value + 1
End With
Application.EnableEvents = False
Target.Value = vendor 'switch from vendor number to vendor name
Application.EnableEvents = True

Else
Application.EnableEvents = False
Target.Value = "" 'clear the value
Application.EnableEvents = True
MsgBox "The Vendor number '" & v & "' entered is not listed....", vbExclamation
End If 'was found
End If 'is a number

End Sub





share|improve this answer























  • Works flawlessly! Thank you for your assistance. However, when recording an additional entry with the same name, it still increases the value by 1 regardless if there's multiple instances of a name.
    – T. Francois
    Nov 14 at 23:40












  • If you use MsgBox vendorCount in that situation what value pops up?
    – Tim Williams
    Nov 14 at 23:57










  • Nothing happens. No message box comes up.
    – T. Francois
    Nov 15 at 0:11










  • Well something should pop up if you put that Msgbox right after vendorCount = ...
    – Tim Williams
    Nov 15 at 0:20










  • Nothing does unfortunately. I'll have to take a stab at it tomorrow, as my brain is fried from messing around with everything earlier.
    – T. Francois
    Nov 15 at 0:37















up vote
0
down vote



accepted










Untested:



Private Sub Worksheet_Change(ByVal Target As Range)
Const RNG_VENDOR As String = "B6:B37,B46:B77"

Dim v, f As Range, vendor, vendorCount

If Target.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(RNG_VENDOR)) Is Nothing Then Exit Sub

v = Target.Value
If IsNumeric(v) And Len(v) > 0 Then

'see if there's a numeric match
Set f = Sheet8.Range("A:A").Find(v, lookat:=xlWhole, LookIn:=xlValues)
If Not f Is Nothing Then
vendor = f.EntireRow.Cells(1, "B").Value 'get the vendor name
'#### edit below to fix lookup range
vendorCount = Application.CountIf(Me.Range("B6:B77"), vendor) 'count any existing
'update the vendors sheet?
With f.EntireRow.Cells(1, "J")
If vendorCount = 0 Then .Value = .Value + 1
End With
Application.EnableEvents = False
Target.Value = vendor 'switch from vendor number to vendor name
Application.EnableEvents = True

Else
Application.EnableEvents = False
Target.Value = "" 'clear the value
Application.EnableEvents = True
MsgBox "The Vendor number '" & v & "' entered is not listed....", vbExclamation
End If 'was found
End If 'is a number

End Sub





share|improve this answer























  • Works flawlessly! Thank you for your assistance. However, when recording an additional entry with the same name, it still increases the value by 1 regardless if there's multiple instances of a name.
    – T. Francois
    Nov 14 at 23:40












  • If you use MsgBox vendorCount in that situation what value pops up?
    – Tim Williams
    Nov 14 at 23:57










  • Nothing happens. No message box comes up.
    – T. Francois
    Nov 15 at 0:11










  • Well something should pop up if you put that Msgbox right after vendorCount = ...
    – Tim Williams
    Nov 15 at 0:20










  • Nothing does unfortunately. I'll have to take a stab at it tomorrow, as my brain is fried from messing around with everything earlier.
    – T. Francois
    Nov 15 at 0:37













up vote
0
down vote



accepted







up vote
0
down vote



accepted






Untested:



Private Sub Worksheet_Change(ByVal Target As Range)
Const RNG_VENDOR As String = "B6:B37,B46:B77"

Dim v, f As Range, vendor, vendorCount

If Target.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(RNG_VENDOR)) Is Nothing Then Exit Sub

v = Target.Value
If IsNumeric(v) And Len(v) > 0 Then

'see if there's a numeric match
Set f = Sheet8.Range("A:A").Find(v, lookat:=xlWhole, LookIn:=xlValues)
If Not f Is Nothing Then
vendor = f.EntireRow.Cells(1, "B").Value 'get the vendor name
'#### edit below to fix lookup range
vendorCount = Application.CountIf(Me.Range("B6:B77"), vendor) 'count any existing
'update the vendors sheet?
With f.EntireRow.Cells(1, "J")
If vendorCount = 0 Then .Value = .Value + 1
End With
Application.EnableEvents = False
Target.Value = vendor 'switch from vendor number to vendor name
Application.EnableEvents = True

Else
Application.EnableEvents = False
Target.Value = "" 'clear the value
Application.EnableEvents = True
MsgBox "The Vendor number '" & v & "' entered is not listed....", vbExclamation
End If 'was found
End If 'is a number

End Sub





share|improve this answer














Untested:



Private Sub Worksheet_Change(ByVal Target As Range)
Const RNG_VENDOR As String = "B6:B37,B46:B77"

Dim v, f As Range, vendor, vendorCount

If Target.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(RNG_VENDOR)) Is Nothing Then Exit Sub

v = Target.Value
If IsNumeric(v) And Len(v) > 0 Then

'see if there's a numeric match
Set f = Sheet8.Range("A:A").Find(v, lookat:=xlWhole, LookIn:=xlValues)
If Not f Is Nothing Then
vendor = f.EntireRow.Cells(1, "B").Value 'get the vendor name
'#### edit below to fix lookup range
vendorCount = Application.CountIf(Me.Range("B6:B77"), vendor) 'count any existing
'update the vendors sheet?
With f.EntireRow.Cells(1, "J")
If vendorCount = 0 Then .Value = .Value + 1
End With
Application.EnableEvents = False
Target.Value = vendor 'switch from vendor number to vendor name
Application.EnableEvents = True

Else
Application.EnableEvents = False
Target.Value = "" 'clear the value
Application.EnableEvents = True
MsgBox "The Vendor number '" & v & "' entered is not listed....", vbExclamation
End If 'was found
End If 'is a number

End Sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 at 20:25

























answered Nov 14 at 23:24









Tim Williams

84.5k96684




84.5k96684












  • Works flawlessly! Thank you for your assistance. However, when recording an additional entry with the same name, it still increases the value by 1 regardless if there's multiple instances of a name.
    – T. Francois
    Nov 14 at 23:40












  • If you use MsgBox vendorCount in that situation what value pops up?
    – Tim Williams
    Nov 14 at 23:57










  • Nothing happens. No message box comes up.
    – T. Francois
    Nov 15 at 0:11










  • Well something should pop up if you put that Msgbox right after vendorCount = ...
    – Tim Williams
    Nov 15 at 0:20










  • Nothing does unfortunately. I'll have to take a stab at it tomorrow, as my brain is fried from messing around with everything earlier.
    – T. Francois
    Nov 15 at 0:37


















  • Works flawlessly! Thank you for your assistance. However, when recording an additional entry with the same name, it still increases the value by 1 regardless if there's multiple instances of a name.
    – T. Francois
    Nov 14 at 23:40












  • If you use MsgBox vendorCount in that situation what value pops up?
    – Tim Williams
    Nov 14 at 23:57










  • Nothing happens. No message box comes up.
    – T. Francois
    Nov 15 at 0:11










  • Well something should pop up if you put that Msgbox right after vendorCount = ...
    – Tim Williams
    Nov 15 at 0:20










  • Nothing does unfortunately. I'll have to take a stab at it tomorrow, as my brain is fried from messing around with everything earlier.
    – T. Francois
    Nov 15 at 0:37
















Works flawlessly! Thank you for your assistance. However, when recording an additional entry with the same name, it still increases the value by 1 regardless if there's multiple instances of a name.
– T. Francois
Nov 14 at 23:40






Works flawlessly! Thank you for your assistance. However, when recording an additional entry with the same name, it still increases the value by 1 regardless if there's multiple instances of a name.
– T. Francois
Nov 14 at 23:40














If you use MsgBox vendorCount in that situation what value pops up?
– Tim Williams
Nov 14 at 23:57




If you use MsgBox vendorCount in that situation what value pops up?
– Tim Williams
Nov 14 at 23:57












Nothing happens. No message box comes up.
– T. Francois
Nov 15 at 0:11




Nothing happens. No message box comes up.
– T. Francois
Nov 15 at 0:11












Well something should pop up if you put that Msgbox right after vendorCount = ...
– Tim Williams
Nov 15 at 0:20




Well something should pop up if you put that Msgbox right after vendorCount = ...
– Tim Williams
Nov 15 at 0:20












Nothing does unfortunately. I'll have to take a stab at it tomorrow, as my brain is fried from messing around with everything earlier.
– T. Francois
Nov 15 at 0:37




Nothing does unfortunately. I'll have to take a stab at it tomorrow, as my brain is fried from messing around with everything earlier.
– T. Francois
Nov 15 at 0:37


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309936%2fcompare-value-in-cell-to-array-and-then-add-value-if-true%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?