Help on modify existing VBA to allow comparison of 2 text cells to work

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
795
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - running into an annoying problem where my comparison of two columns doesn't work when I check for a simple true/false statement. I am comparing Column K to Column U with formula K13=U13, data is the same but says false.

Column K (format of row K is TEXT)

Column U
VBA Code:
    .Range("U13:U" & lr).NumberFormat = "General"
    .Range("U13:U" & lr).Formula = "=IFERROR(VLOOKUP(D13,'NAS D'!$A$6:$Y$10000,8,0),"""")"
    .Range("U13:U" & lr).NumberFormat = "@"

even if i do a sample test it doesn't work - but does if i click into column U. how do I get VBA to do the same and click into each cell to get it to work? To note data set is LARGE over 10k rows. so clicking into each cell would kill performance. any help is appreciated. thanks in advance.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I am guessing that the data in NAS D doesn't really match. Find a spare cells where you can put
Excel Formula:
=LEN(K13)
and
Excel Formula:
=LEN(U13)
to see if they match. If they do not match, look for extra spaces either in K13 or in the matching cell in sheet NAS D.
 
Upvote 0
I am guessing that the data in NAS D doesn't really match. Find a spare cells where you can put
Excel Formula:
=LEN(K13)
and
Excel Formula:
=LEN(U13)
to see if they match. If they do not match, look for extra spaces either in K13 or in the matching cell in sheet NAS D.
They match 9 to 9 same characters and all. Just not sure why I must physically click into column U, then press enter in order for it to work? that part i dont understand.
 
Upvote 0
Well, something is different between those two cells, if you have correctly showed your formula (the code doesn't really matter).

Do you have any way to share your file so we can look at the data?

I must physically click into column U, then press enter
I don't understand what you mean by this. What are you doing that requires this?
 
Upvote 0
it is confidential. But I can mock-up a test that interacts the same way

I don't understand what you mean by this. What are you doing that requires this?
At the end of the code I export the sheet removing all formulas. when reviewing what is occurring i manually put the formula in (K13=U13) and compared where it again was "false" but then after clicking into the cell (U13) and pressing enter the condition changed to "TRUE"
 
Upvote 0
I think I inadvertently found it. I will test the next few days to validate. the location of my vlookup the column was set as "general." So i think that would make my formatting inconsistent for the compare.
 
Upvote 0
No not the location of the formula where the formula was sourcing for the data. So I think and could be wrong. if it pulls a vlookup of a "general" format then compares it to a text it was failing. i did it on my test ill send it to you shortly.
 
Upvote 0
VBA Mockup_formatting.xlsm
ABCDEFG
1CurrentNew
2other dataother dataUNIQUE SKUVLOOKUP SKU (GENERALVLOOKUP SKU TEXT)COMPARE GENERALCOMPARE TEXT
31A921333909213339092133390FALSETRUE
42B921333919213339192133391FALSETRUE
53C921233919212339192123391FALSETRUE
64D971233919712339197123391FALSETRUE
75E97123E919.7123E+9597123E91FALSETRUE
86F971ABE91971ABE91971ABE91TRUETRUE
97G976233919762339197623391FALSETRUE
108H976237919762379197623791FALSETRUE
119I976237019762370197623701FALSETRUE
1210J976237119762371197623711FALSETRUE
TEST
Cell Formulas
RangeFormula
D3:D12D3=IFERROR(VLOOKUP(B3,Inventory!A:B,2,FALSE),"")
E3:E12E3=IFERROR(VLOOKUP(B3,Inventory!D:E,2,FALSE),"")
F3:F12F3=IF(B3<>"",C3=D3,"")
G3:G12G3=IF(C3<>"",C3=E3,"")


VBA Mockup_formatting.xlsm
ABCDE
1GENERALGENERALTEXTTEXT
2A92133390A92133390
3B92133391B92133391
4C92123391C92123391
5D97123391D97123391
6E9.71E+95E97123E91
7F971ABE91F971ABE91
8G97623391G97623391
9H97623791H97623791
10I97623701I97623701
11J97623711J97623711
Inventory
 
Upvote 0
Column U
VBA Code:
.Range("U13:U" & lr).NumberFormat = "General"
.Range("U13:U" & lr).Formula = "=IFERROR(VLOOKUP(D13,'NAS D'!$A$6:$Y$10000,8,0),"""")"
.Range("U13:U" & lr).NumberFormat = "@"
Note that changing the number format of column U to Text after it has a number entered by the formula, does not change that number to text.
So I believe that you are still comparing the number 92133390 to the text "92133390" & hence the FALSE result.

If you want the VLOOKUP to return the number as text, try changing the formula to this and leave the column formatted as General
VBA Code:
.Range("U13:U" & lr).Formula = "=IFERROR(VLOOKUP(D13,'NAS D'!$A$6:$Y$10000,8,0)&"""","""")"
 
Upvote 0

Forum statistics

Threads
1,215,771
Messages
6,126,797
Members
449,337
Latest member
BBV123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top