Replacing text in excel from a static table - excel

I have a report that is sent to me daily that only supplies IP addresses and would like to create a macro that would look up the address to host conversion from another table (external to the excel sheet report). So that when its executed, the IP address would be replaced with the actual hostname.
Date/Time Detected Source IP Address Destination IP Address
6/19/2013 15:46 172.16.16.40 172.16.4.10
6/19/2013 15:46 172.16.16.40 *
6/19/2013 15:02 172.16.16.40 *
6/19/2013 15:02 172.16.16.40 *
6/19/2013 15:02 172.16.16.40 *
6/19/2013 15:02 172.16.16.40 *
In this example, I would have a table that would have an IP address and Host address (from a dns export table), that I would like to do a replace Source IP with it's hostname from my daily reports. The dns table is static, the daily reports would be populated with a replace IP with hostname from the static dns table.

I created a very simple example of how to do this:
Right now (to make it easier to make the picture) the DNStable is a named range (green background) in the same sheet - but it could be in another sheet/workbook. The VLOOKUP function attempts to find an exact match (fourth argument FALSE means "exact match") between the first argument (the "Source IP Address") and the first column in that table; it returns the value in column 2 if found, or #N/A if not found.
To do the same thing when the DNS lookup is a different file, use the following formula:
=VLOOKUP(B2,DNSlookup.xlsx!DNStable,2, FALSE)
Where the DNSlookup.xlsx file contains a named range DNStable as before:
As long as that file is open in your copy of Excel, you're good - they don't have to be in the same file. Now copy this formula into cell D2, and drag it all the way down. Cool trick: if you select the cell, then double-click the little "dragbox" in the bottom right-hand corner, it will automatically fill all the way down (as many cells as there are cells immediately to the left of it). Try it!
Note - if you now close both the DNS lookup file and this file, and then open it again, you will get a warning about "updating external links". At that point you will see the formula has changed to something like this:
=VLOOKUP(B2,'X:\code\DNSlookup.xlsx'!DNStable,2, FALSE)
As you can see, it's created a link to the location where the other file is kept - but it also kept the value of the last successful lookup.
This ought to work for you.

Related

Multiple IFS to check for three different values in on cell

I have 3 sheets S1, S2, and S3 that I use on a 4th sheet that I use formulas to index and match IP addresses. S1 contains a mapping of NAT IPs for the client's A private subnet and S2contains a mapping of NAT IPs for the client's B private subnet i.e. (A) 10.1.1.1 (B2) 100.
I use S4 A2 - AX and input an IP that I want to look i.e 100.100.1.1, B2 will Index and match S3 and return the IP in question which tells me it exists in the database. then in C2, I want to use the value in B2 and index and match the proper sheet based on the 1st & 2nd octet of the IP... i.e if the 1st two octets start with 100.100.x.x then index and match S1 if the IP starts with 100.200. then look it up on S2 and if the IP starts with 10.x.x.x I want to look it up on the sheets and return its mapped NAT IP if it exists.
=IFS(LEFT(A2,8)="100.100.",INDEX('S1.csv'!$C:$C,MATCH(B2,'S1.csv'!$F:$F,0)),LEFT(A2,8)="100.200.",INDEX('S2.csv'!$C:$C,MATCH(B2,'S2.csv'!$F:$F,0)))
I am stuck on how to do these check those three conditions :( I tried IFS, IFERROR, OR, AND but still not able to figure it out. any help suggestions are highly appreciated.
what I am trying to accomplish here is:
check if cellA2 contains an IP of 100.100.x.x, if true lookup its nat address. if the IP starts with 100.200 return its real IP from the client's B sheet and if it is not 100.100.x.x nor 100.200.x.x and it starts with 10. or 65 etc.. return its NAT'd IP.
thank you in advance
I think you should nest the if statements for each case. Another tip: you could use the LET function to capture the LEFT 7 characters of the IP address and store it in a variable (in my case called domain):
=LET(domain,LEFT(A2,7),IF(domain="100.100",[do the index/match in S1],IF(domain="100.200",[do the index/match in S2],[do the index/match in S3])))

Using Connection Names

Is there anyway to use the Connection Names rather than the connection link in the Excel formulas?
Example:
Connection Name - Test1
Connection Link - www.www.www.com
Current Equation - =IF('www.www.www.com[test1.xlsm]Sheet1!'K1=0, "--", 'www.www.www.com[test1.xlsm]Sheet1!'K1)
Desired Equation - =IF('Test1'Sheet1!K1=0, "--", 'Test1'Sheet1!K1)
Does anyone know if its possible? My addresses are really long and would be easier.
One option is to use Indirect - which uses the content of a cell in a formula - rather than its address.
As such, for your example - you could have the string 'www.www.www.com[test1.xlsm]Sheet1!'K1 in a cell - such as A1 then in your formula you could refer to it as =IF(INDIRECT(A1)>0,"--",INDIRECT(A1))
Other than that, you'd probably have to look at a custom vba function. (I'll not go into that with the lack of tag)

Invalid column name in excel works in SQL

I have a query that I wrote using Query Analyzer. It works in the Analyzer but when I run it in Excel I get an invalid column name error. the error does not list the entire column name. If I put square brackets around the entire column name the error lists the entire column name.
If i run the code as follows.
Select
tblarInvoice.shipfromlocation
From
tblarInvoice
Where
tblarInvoice.dateshipped >= '10/01/2014'
I get the error of:
Invalid column name'shipfrom'
If I run the code with square brackets around it i get the error of:
Invalid column name'shipfromlocation'
Likely something to do with the driver being used.
Perhaps there's a limit on column length.
Try and alias the column Name to something shorter.
It may also have trouble with the name 'FROM' in the column name.
Could you create a view in the database that selects from the table but aliases the column name .
The driver may parse the SQL see FROM think it's a reserved word and give up. The [] may put you beyond a 30 character limit as well... so ... try something different use column name alias and or select from the view?
SELECT tblarInvoice.shipfromlocation as sfl
Root Cause is one of two things or a combination:
When processing the SQL string the Driver sees "FROM" and throws an error
When you wrap the name in [] it extends the field name to be > 30 characters which in some drivers is a limit.
You could isolate root cause by altering the alias on the view to be something like sFROMLocation If you get an error you know the driver has probelms parsing column names with FROM in them.
If you alter it to sFroLocation does it then work?
Additionally you could set the column name to tblarinvoiceshipfrolocationtest if an error is returned you know that column names > 30 are problems for the driver being used.
then change it to
tblarinvoiceshipfrolocationtst if it works then you know a 31 length name doesn't work. a 30 does. again evidence driver can't support column names longer than 30 characters.
Just depends if you want to get to root cause :P

Find any part of a string of text from a range of cells

I have two lists of street addresses that have a combination of street numbers and names in one cell. One list is a key, if you will, of how the addresses are labeled in our company, and the other list is all of the addresses that customers used to get a package to us. For example![Address Key][1]
is the correct address format. The other list has errors within the address because there may be errors with order, fat fingered street numbers, or spelling errors of the street names. I'd like to create a formula or find a way that looks for any portion of the second list, and have it return a "yes" or "no" if it is an address in the address key. The second list that I need to lookup with is below.![enter image description here][2]
You can see that the addresses that the customers enter do not match how we label our addresses. Hopefully there is a way for me to look up any part of the address that they entered against our key, and have it return a value that is associated with each address in the key. For example, the first address is location 100. Even though the customer list doesn't have that address entered correctly, i'm hopping it can find a part of the address they entered in our list.
Thanks,
Jay
You can try using a Vlookup with a 'TRUE' parameter in the RangeLookup argument. That way the Vlookup will return an approximate match against your company list. You may need to reformat the data a bit (e.g. concatenate house number and street name together) and do some iterations to get the final result that you need. You haven't added any screen shots so I can't see the exact format of your data.

Pull An Address Apart From Single Cell In Excel

I have 2002 addresses which have all been compiled into a single cell during the download process from my server; in most cases, the hash (#) symbol is used to separate fields (such as Line 1, Line 2, City, Postcode).
I have spent a lot of time trying combinations of LEFT, MID and other functions, but to no avail; the problem is that as there are so many addresses, and not all of them have the same number of characters for each field (such as Postcode - some will have 6 characters (including blank space), where some others will have five or more/fewer), there doesn't appear to be a one-size-fits-all solution that I can enter once and then use Excel's auto-fill handle/feature to complete the process for all records.
Here is a sample of my data (which has been anonymised):
44A THE ADDRESS#EALING#LONDON#W1 1WW#
541 PARSON PLACE#HENDON#LONDON#NW4 4WN#
SOMEBODY PRACTICE CHALKHILL PCC THE WELFORD CTR#11B CHALKHILL AVENUE#WIMBLEDONE MIDDX#HH9 9HH#
THE SEBELMONT MEDICAL CLINIC 18 EASTERN ROAD#SOUTHALL#MIDDLESEX#UN1 1NU#
130 FINGOVER COURT#REDBUS STREET#CAMBERWELL#SE5 5ES#
KING'S ELBOW MEDICAL CENTRE 17F STAGLAND LANE#KINGSBURY#MIDDX#NW9 9WN#
10 LADYFOOT ROAD RUISLIP#MIDDLESEX#HA4 4AH#
I want to be able to extract everything between the hash symbols (excluding/omitting the hash symbols themselves) and I am dedicating four columns to store this data: Address Line 1, AL2, AL3, Postcode.
Going by the first example (44A THE ADDRESS#EALING#LONDON#W1 1WW#) which resides in a single cell, I hope to achieve something like the following outcome:
AL1 AL2 AL3 POSTCODE
44A THE ADDRESS EALING LONDON W1 1WW
It doesn't matter if some of the address sections appear under the wrong column - I can very easily rectify this and can even add another column; I simply want to be able to extract the data from the single cell.
If you import the data as a text file, you can normally select the delimiter.
File->open
<select the file from the dialogue box>
This dialogue box should appear, after clicking next, it will appear as above, at which point, you can select a hash as a delimiter- instant self data sorting!

Resources