Combing 2 Columns That Contain Over 16 Numbers And Have Them Display Correctly

dmcgetti

Board Regular
Joined
Feb 16, 2015
Messages
66
I have 2 columns that I am combing via VBA, the first column contains invoice numbers that are 7 digits long and the second column contains part numbers that are 12 digits long and contain a "-" and a "*". Everything works fine until I remove the "-" and the "*", I get a bunch of "#"'s and if I convert the column to text I get a scientific notation. I know that if I was manually typing in the cell I could add " ' ", but how do I do that, or similar, via VBA.

Code:
    Range("Table1[Lookup]").NumberFormat = "Text"    
    Range("Table1[Lookup]").FormulaLocal = "=[@InvoiceNumber]&[@PartNumber]"
    Range("Table1[Lookup]").Copy
    Range("Table1[Lookup]").PasteSpecial Paste:=xlPasteValues
    Range("Table1[Lookup]").NumberFormat = "Text"
    Range("Table1[Lookup]").Select
    Selection.Replace What:="~*", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("Table1[Lookup]").Select
    Selection.Replace What:="-", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
[TABLE="width: 427"]
<colgroup><col><col><col><col span="2"></colgroup><tbody>[TR]
[TD]inv[/TD]
[TD]part[/TD]
[TD]combine[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1234567[/TD]
[TD]987-65432*11[/TD]
[TD]1234567987-65432*11[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 2"]is this what you want ?[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
[TABLE="width: 406"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD]inv[/TD]
[TD]part[/TD]
[TD]combine[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1234567[/TD]
[TD]987-65432*11[/TD]
[TD]1234567987-65432*11[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 2"]is this what you want ?[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]or this[/TD]
[TD]12345679876543211[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
[TABLE="width: 406"]
<tbody>[TR]
[TD]inv
[/TD]
[TD]part
[/TD]
[TD]combine
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1234567
[/TD]
[TD]987-65432*11
[/TD]
[TD]1234567987-65432*11
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 2"]is this what you want ?
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]or this
[/TD]
[TD]12345679876543211
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

This
 
Upvote 0
I have 2 columns that I am combing via VBA, the first column contains invoice numbers that are 7 digits long and the second column contains part numbers that are 12 digits long and contain a "-" and a "*". Everything works fine until I remove the "-" and the "*", I get a bunch of "#"'s and if I convert the column to text I get a scientific notation. I know that if I was manually typing in the cell I could add " ' ", but how do I do that, or similar, via VBA.

Code:
    Range("Table1[Lookup]").NumberFormat = "Text"    
    [B][COLOR="#FF0000"]Range("Table1[Lookup]").FormulaLocal = "=[@InvoiceNumber]&[@PartNumber]"[/COLOR][/B]
    Range("Table1[Lookup]").Copy
    Range("Table1[Lookup]").PasteSpecial Paste:=xlPasteValues
    Range("Table1[Lookup]").NumberFormat = "Text"
    Range("Table1[Lookup]").Select
    Selection.Replace What:="~*", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("Table1[Lookup]").Select
    Selection.Replace What:="-", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
Does changing the highlighted line of code to this make it work for you...

Range("Table1[Lookup]").FormulaLocal = "=""'""&[@InvoiceNumber]&[@PartNumber]"
 
Upvote 0
No luck, thanks
Describe "no luck" for me. What actually happened or didn't happen that should have happened? Just so you know, the code worked for me when I set up an Excel table object, named it "Table1" and put columns with the headers "InvoiceNumber", "PartNumber" and "Lookup" in it and then put the values 'oldbrewer' showed in the columns he labeled "inv" and "part" (Message #3 ) into them.
 
Last edited:
Upvote 0
Describe "no luck" for me. What actually happened or didn't happen that should have happened? Just so you know, the code worked for me when I set up an Excel table object, named it "Table1" and put columns with the headers "InvoiceNumber", "PartNumber" and "Lookup" in it and then put the values 'oldbrewer' showed in the columns he labeled "inv" and "part" (Message #3 ) into them.

Scratch that, it did "work", I had a typo.

That combines them, but the " ' " is in the cells that are all numbers, and I need the cells to just contain the InvoiceNumber and PartNumber because that column is used as look up field.
 
Last edited:
Upvote 0
Scratch that, it did "work", I had a typo.

That combines them, but the " ' " is in the cells that are all numbers, and I need the cells to just contain the InvoiceNumber and PartNumber because that column is used as look up field.
The apostrophe should only be appearing in the Formula Bar... it should not be visible in the cell itself. As long as this is the case, your lookup should work as long as what you are looking up is text (otherwise all of the digits will not be correct in the value you are looking up). If you are still having trouble, show us the code that is doing the look up.
 
Upvote 0
The apostrophe should only be appearing in the Formula Bar... it should not be visible in the cell itself. As long as this is the case, your lookup should work as long as what you are looking up is text (otherwise all of the digits will not be correct in the value you are looking up). If you are still having trouble, show us the code that is doing the look up.

It is showing up in the cell, but it is working none the less, so thanks!
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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