excel coulmn to lookup table in access

frankee_gee

Board Regular
Joined
Mar 3, 2008
Messages
144
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Please help,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I have a spreadsheet with 5400 records/rows. This will be imported into an Access 2007 DB. This DB has multiple tables including lookup tables. <o:p></o:p>
<o:p></o:p>
In Excel the contents of column "D" titled UnitID, must be converted to numbers, which will very from 1 thru 96 depending on the content.<o:p></o:p>
<o:p></o:p>
All 96 lookup values are in a second sheet in this excel book. <o:p></o:p>
<o:p></o:p>
Say in sheet "Tag_Log" cell D6 = Boiler<o:p></o:p>
<o:p></o:p>
In sheet "Units" B29 = Boiler and A29 = 28<o:p></o:p>
<o:p></o:p>
Want "Tag_Log" cell D6 = 28<o:p></o:p>
<o:p></o:p>
How can this be accomplished?<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Want the Current UnitID column in Sheet: “Tag_Log” (Data).<o:p></o:p>
<o:p> </o:p>
To be replaced by UnitID column in Sheet: “Units”(Lookup Table).<o:p></o:p>
<o:p> </o:p>
Must match UnitID column in sheet: Tag_Log to UnitNo in sheet: “Units”. Then take the number in column A UnitID in that same row and replace the contents of UnitID in sheet: Tag_Log.<o:p></o:p>

How can this be done?


Thanks for your help.

Frank.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hey Frankee,

Looking at your posting history it looks like your about as new to this as I am, but have a pair of solutions.

Typically I would use VLOOKUP to return the values from the "Units" sheet into the "Tag_Log" sheet. However to do this involves some very minor tweaking.

On the "Units" sheet, switch the order of columns A and B so that A contains the text (such as boiler) and column B contains UnitID
On the "Tag_Log" sheet, insert a column just after the 'D' column. In your newly inserted 'E' column in cell E2 insert the following formula; =VLOOKUP(D2,Units!A:B,2,0)



The second solution is probably more dangerous. I only say that because I am only starting to learn VB scripting. :LOL: This may not be the most efficient code but it worked smoothly on my machine. The code does make a few assumptions;
1) The sheets names are always as you described
2) The data is always in the columns you described
3) D2 is where the data is to start being replaced

The script takes about 6-8 seconds to run through all 5400 lines on my machine.

Code:
Sub UnitID()

    Application.DisplayAlerts = False
    Application.ScreenUpdating = False

    Dim CurVal As String
    Dim Rng As Range

    On Error Resume Next
    
    Range("D2").Select
    
    Do While Not IsEmpty(ActiveCell)
        
        CurVal = ActiveCell.Value
       
        ActiveCell = "Home"
        
        With Worksheets("Units").Range("B:B").Select
            Selection.Find(What:=CurVal, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
                :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
                False, SearchFormat:=False).Select
        End With

        Selection.Offset(0, -1).Select
        
        NewVal = ActiveCell.Value
      
        With Sheets("Tag_Log").Range("D:D").Select
            Selection.Find(What:="Home", After:=Cells(1, 4), LookIn:=xlFormulas, LookAt _
                :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
                False, SearchFormat:=False).Select
        End With
        ,
        Selection.Replace What:="Home", Replacement:=NewVal
        ActiveCell.Offset(1, 0).Select
        
    Loop

End Sub
Hope one of these helps you,
J Ericson
 
Upvote 0
J,

Thanks for your reply.

Your first solution:

Will not convert the cells where the number is stored as TEXT. Any idea why?

Thanks,

Frankee
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

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