Hello,
This is my first post but I do frequent these forums often trying to figure out how to fix my VBA codes, but I am still struggling with my current issue.
Here is what I am trying to do:
I am comparing 2 worksheets to see if Product A is on Sheet B, and I have about 80,000 lines to go through, so in Excel I use =IF(ISNA(VLookup(arg1,arg2,arg3,arg4)),"N","Y"), this will return a simple yes it is on the sheet, or a no it is not.
I've been trying to do this in VBA and am having some problems, so first I created a loop to do exactly what I did before
This didn't work because it didn't know what to do when the product was not found so I got a Vlookup error, I added an "On Error GoTo" command and the only thing I get is an "N", which I know to be incorrect.
I was able to get Vlookup to work, see the screenshot here, Column D is the lookup value, Column G and Y are the results. What I am trying to do from here is to convert all the on numbers in either column G or Y to text "Y" and I am not sure how to do this...I tried the following IF - THEN code but it didn't change anything.
I also tried to code the IF portion of the code like this, which also did nothing
This seems like it would such a simple thing to do but I am having the hardest time converting these numbers to a simple Y. Any help would be appreciated,
Thanks
This is my first post but I do frequent these forums often trying to figure out how to fix my VBA codes, but I am still struggling with my current issue.
Here is what I am trying to do:
I am comparing 2 worksheets to see if Product A is on Sheet B, and I have about 80,000 lines to go through, so in Excel I use =IF(ISNA(VLookup(arg1,arg2,arg3,arg4)),"N","Y"), this will return a simple yes it is on the sheet, or a no it is not.
I've been trying to do this in VBA and am having some problems, so first I created a loop to do exactly what I did before
Code:
Sub Columnformatting1()
'// Convert Long Integer to Y
For i = 1 To Range("D200000").End(xlUp).Row - 1
Range("G" & i + 1).Value = WorksheetFunction.If(WorksheetFunction.IsNA(WorksheetFunction.VLookup(Range("D" & i + 1).Value, Range("Vaccines")), 1, 0), "N", "Y")
Range("Y" & i + 1).Value = WorksheetFunction.If(WorksheetFunction.IsNA(WorksheetFunction.VLookup(Range("D" & i + 1).Value, Range("EXDS")), 1, 0), "N", "Y")
Next
Resume Next
End Sub
This didn't work because it didn't know what to do when the product was not found so I got a Vlookup error, I added an "On Error GoTo" command and the only thing I get is an "N", which I know to be incorrect.
I was able to get Vlookup to work, see the screenshot here, Column D is the lookup value, Column G and Y are the results. What I am trying to do from here is to convert all the on numbers in either column G or Y to text "Y" and I am not sure how to do this...I tried the following IF - THEN code but it didn't change anything.
Code:
Sub Columnformatting1()
'// Convert Long Integer to Y
On Error GoTo NotFound:
For i = 1 To Range("D200000").End(xlUp).Row - 1
Range("G" & i + 1).Value = WorksheetFunction.VLookup(Range("D" & i + 1).Value, Range("Vaccines"), 1, 0)
Range("Y" & i + 1).Value = WorksheetFunction.VLookup(Range("D" & i + 1).Value, Range("EXDS"), 1, 0)
Next
NotFound:
Range("G" & i + 1).Value = "N"
Range("Y" & i + 1).Value = "N"
Resume Next
If Range("G" & i + 1).Value = "N" Then
Range("G" & i + 1).Value = "N"
Else
Range("G" & i + 1).Value = "Y"
End If
If Range("Y" & i + 1).Value = "N" Then _
Range("Y" & i + 1).Value = "N"
Else
Range("Y" & i + 1).Value = "Y"
End If
End Sub
I also tried to code the IF portion of the code like this, which also did nothing
Code:
If Range("G" & i + 1).Value <> "N" Then
Range("G" & i + 1).Value = "Y"
End If
If Range("Y" & i + 1).Value <> "N" Then _
Range("Y" & i + 1).Value = "Y"
End If
This seems like it would such a simple thing to do but I am having the hardest time converting these numbers to a simple Y. Any help would be appreciated,
Thanks