hi
excel 2007, windows 7
I have a list of terms in col a (103 terms) and a list of company names (674 names) in col b and col c, result to be in col e
I want to check each of the terms in column a, to see if it's in the list in col b and if found, copy the company name in col c into col e.
the following code works fine:
but when I try to loop down the list of terms in col a against the list of company names in col b, I can't get the absolute references to work:
on the first pass, i = 2 and j = 2, when I stop @ the line: If ActiveCell.Value = "not found" Or ActiveCell.Value = "" Then
if I hover over activecell.value it returns activecell.value=empty
if in the immediate window I type ?activecell.value it returns a blank
if I type ?activecell.value = empty, it returns TRUE
if I hover over formula_a it returns formula_a="=if(iserror(find(A2,B2)),R2,C2)"
if in the immediate window I type ?formula_a, it returns =if(iserror(find(A2,B2)),R2,C2)
if I hover over activecell.formular1c1, it returns activecell.formular1c1 = ""
in the immediate window if I type ?activecell.formular1c1 it returns a blank
when I stop @ line end if,
if I hover over activecell.value, it returns activecell.value=0
if in the immediate window I type ?activecell.value it returns 0
if I type ?activecell.value = empty, it returns TRUE
if I hover over formula_a it returns formula_a="=if(iserror(find(A2,B2)),R2,C2)"
if in the immediate window I type ?formula_a, it returns =if(iserror(find(A2,B2)),R2,C2)
if I hover over activecell.formular1c1 it returns activecell.formular1c1="=if(iserror(find(A2,B2)),R2,C2)"
if in the immediate window I type ?activecell.formular1c1 it returns =IF(ISERROR(FIND(A2,B2)),R2,C2)
however:
if I click in cell E2, the value showing in the cell is 0 and the formula is =IF(ISERROR(FIND('A2','B2')),$2:$2,$B:$B)
on the next j loop, where i=2 and j=3, I get the same results replacing B2 with B3 and C2 with C3.
I've tried everything I can think of, all suggestions on the web - though none that deal with looping through a list of values - all manner of recording a macro and editing the vba code.
as you can see, I've created the formula correctly and even assigned the formula to the active cell but the value and formula in the active cell just aren't correct.
I'm now am at wit's end or the end of my capabilities.
any suggestions would be greatly appreciated, or is this just not possible.
thanks
kim
excel 2007, windows 7
I have a list of terms in col a (103 terms) and a list of company names (674 names) in col b and col c, result to be in col e
I want to check each of the terms in column a, to see if it's in the list in col b and if found, copy the company name in col c into col e.
the following code works fine:
Code:
Sub find_lcd_in_gm_co_name_list_single()
For j = 2 To 675
col_e = "E" & Trim(Str(j))
Range(col_e).Select
ActiveCell.FormulaR1C1 = "=IF(ISERROR(FIND(R2C1,RC[-3])),""not found"",R2C3)"
Range(col_e).Select
Next j
End Sub
but when I try to loop down the list of terms in col a against the list of company names in col b, I can't get the absolute references to work:
Code:
Sub find_lcd_in_gm_co_name_list_looping()
Dim col_a As String
Dim col_b As String
Dim col_e As String
Dim i As Integer
Dim j As Integer
Dim formula_a As String
Dim not_found As String
not_found = "not found"
For i = 2 To 103
col_a = "A" & Trim(Str(i))
For j = 2 To 675
col_b = "B" & Trim(Str(j))
col_c = "C" & Trim(Str(j))
col_e = "E" & Trim(Str(j))
formula_a = "=if(iserror(find(" & col_a & "," & col_b & "))," & "R2" & "," & col_c & ")"
Range(col_e).Select
If ActiveCell.Value = "not found" Or ActiveCell.Value = "" Then
ActiveCell.FormulaR1C1 = formula_a
Range(col_e).Select
End If
Next j
Next i
End Sub
on the first pass, i = 2 and j = 2, when I stop @ the line: If ActiveCell.Value = "not found" Or ActiveCell.Value = "" Then
if I hover over activecell.value it returns activecell.value=empty
if in the immediate window I type ?activecell.value it returns a blank
if I type ?activecell.value = empty, it returns TRUE
if I hover over formula_a it returns formula_a="=if(iserror(find(A2,B2)),R2,C2)"
if in the immediate window I type ?formula_a, it returns =if(iserror(find(A2,B2)),R2,C2)
if I hover over activecell.formular1c1, it returns activecell.formular1c1 = ""
in the immediate window if I type ?activecell.formular1c1 it returns a blank
when I stop @ line end if,
if I hover over activecell.value, it returns activecell.value=0
if in the immediate window I type ?activecell.value it returns 0
if I type ?activecell.value = empty, it returns TRUE
if I hover over formula_a it returns formula_a="=if(iserror(find(A2,B2)),R2,C2)"
if in the immediate window I type ?formula_a, it returns =if(iserror(find(A2,B2)),R2,C2)
if I hover over activecell.formular1c1 it returns activecell.formular1c1="=if(iserror(find(A2,B2)),R2,C2)"
if in the immediate window I type ?activecell.formular1c1 it returns =IF(ISERROR(FIND(A2,B2)),R2,C2)
however:
if I click in cell E2, the value showing in the cell is 0 and the formula is =IF(ISERROR(FIND('A2','B2')),$2:$2,$B:$B)
on the next j loop, where i=2 and j=3, I get the same results replacing B2 with B3 and C2 with C3.
I've tried everything I can think of, all suggestions on the web - though none that deal with looping through a list of values - all manner of recording a macro and editing the vba code.
as you can see, I've created the formula correctly and even assigned the formula to the active cell but the value and formula in the active cell just aren't correct.
I'm now am at wit's end or the end of my capabilities.
any suggestions would be greatly appreciated, or is this just not possible.
thanks
kim