How to get the table name and column name from data model of selected cell in excel API - vba

Currently I am working on Excel add in which is present in office developer tools.
But I am very much new to this. I have a requirement which is described in below lines.
Is there a way to get table name and column name from where the data is fetched(i.e if a cube formula contains a cell name as C1 then is there any possibility to get table name and column name corresponding to value in C1 in data model) based on the cell names that are present in cube formula. Currently I am getting all the Cell values corresponding to Cell names in cube formula.
But I didnt find a way to get the table specific details.
Could you please help me in achieving the above scenario.

use the watch window to examine the Range("c1") object
columnNumber = Range("c1").Column
tableName = Range("c1").ListObject.Name

Related

generate a hyperlink in sheet linking to matched data found in a different sheet

I have two different sheets in a workbook with data, all of this data is organized by Site ID's. What I want to do is use these site ID's to create a hyperlink in one of the data sheets that when clicked takes the user to the corresponding Site ID in the other sheet. The sheet name where I want to write the hyperlinks to is called "Report_Manual" and I want to write hyperlinks down every row down the first column. The sheet that I am hyperlinking to is called "Data". The premise Ids are located in column C for sheet "Report_Manual" and column K in sheet "Data". Below is an a ttempt of what I was trying to generate in excel for a single cell formula however the issue I ran into for this formula is that the Premise ID's in sheet "data" are variant data type while the Premise ID's in sheet "Report Manual" are integer data type. This makes even a simple formula like the one below not get any matches as the data types being matched aren't the same.
=HYPERLINK("#"&CELL("address",INDEX(Data!K3:K580001,MATCH(C3,Data!K3:K580001,0))),C3)
If anyone has any idea of a macro to solve this issue that would be extremely helpful.
If the IDs in "Data" are text, try changing your match lookup value to text:
=HYPERLINK("#"&CELL("address",INDEX(Data!K3:K580001,MATCH(TEXT(C3,0),Data!K3:K580001,0))),C3)

Find first non-blank cell in column that meets criteria in another column

I've compiled multiple spreadsheets containing sporadic employee information, and I'm now trying to consolidate all of the information to remove duplicates and blanks. The formula below is my starting point, but if the first cell that meets that criteria is blank, it returns a blank. I want it to find the next cell that meets that criteria but has a value.
=INDEX(Working!C:C,MATCH($A3,Working!$B:$B,0))
Below is what the Working tab looks like, which contains the master list of data including blanks and duplicates. Working!C:C is the list of last names; $A3 is the Employee ID I'm hoping to retrieve data for, and Working!$B:$B is the list of Employee IDs. I'll be doing this for many columns, so to illustrate this, in the table example below I've shown that Column D is the phone number. Any help you can provide is appreciated!
Column B-------C-------D
---------287-----Doe----blank
---------287-----blank---333-333-3333
---------287-----Doe----blank
Use the following array formula:
=INDEX(Working!C$1:C$100,MATCH(1,($A3 = Working!$B$1:$B$100)*(Working!C$1:C$100<>""),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.
Please note that with an array formula the references need to be the smallest range possible that covers the dataset.

How to reference a specific cell location within a changing table

I am not sure how, if at all, this can be done. Basically I have a report that is generated from SalesForce for some co-workers. It exports to Excel in this nice little table. Depending on their team, they filter the results and then filter the month (fiscal year in this case).
What I want to do is have text populate at the top which is based on the text that is in the first cell in the column C (not including header row of course) when they filter. How do I go about referencing the spot where C4 is currently when they select Team "White-1" and Fiscal Year "Aug"? That cell will become hidden and I will need to pull the data from C6 which HAPPENS to be in the location that C4 was just in before being hidden.
Here is an image of the report in Excel as well as the "location" that I want to reference no matter the filtering that the employee does:
Report
I assume VBA will be needed. Preferably I want to generate the text in A1
If you are ok with adding a "Helper Column" you can do the following to get the results you are wanting:
Add a column between B and C Give it a header of some kind I used "Helper". Then in this new Column use use the formula =Row() to generate a number for each row.
You can hide this column now if you want.
Then in whichever cell you want the answer you seek enter the following formula:
=Vlookup(Aggregate(5,5,C:C),C:D,2,false)
Now you can filter all you want and you should get the result you wanted.

using SQL query to populate Excel cell

How can I have a cell populated by a sql query?
For example, if a user manually input a part number into cell A1, cell A2 would populate by completing a query using A1 as a parameter.
Something like:
=select table.desc from table where table.partNo = 'A1'
Hope this makes sense.
Depends whether you want to populate cell by cell or by range.
I have used EPPlus along with C# to populate excel templates.
In our case the values are stored in database after the rule evaluation for each cell and then its either gets displayed on screen or exported to excel.
Its not a few lines of code which I can paste it here but you can try below:
1. Define rules with the sql criteria and definition that defines the coordinates of cell
2. Evaluate rules and persist the values
3. Display the values
Ping me if you need more help on this

#REF! result when using INDEX function in Excel

I am trying to create a couple of reports from data on another Excel worksheet based on the value in a drop down list. I am using the MATCH and INDEX functions and have created Named Ranges of the columns of data. I am able to get the first value I want in the report but none of the others, even though when I debug by evaluating the formula it points to the right cell but still displays #REF! instead of the actual value from the referenced cell.
I'll do my best to make this clear:
In "POST_Data" worksheet I have 4 columns titled Course Name, Course Length, Attendee and Date Attended. Currently I have 33 rows of data (plus the header row) but I need the reports to be dynamic since new data will be added from time to time.
I have created Dynamic Named Ranges of the data using the OFFSET function (e.g. for the Course Name data I have a NameRange called CourseNamesData = OFFSET(POST_Data!$A$2,0,0,COUNTA(POST_Data!$A:$A),1)
In the "DashBoard_and_Data Entry" worksheet I have a two report areas: one to report the Course Name and Date Attended for a specified Attendee (specified by a drop down list in cell C7) and the other report to provide the Attendee Name and Date Attended for a specified Course Name (specified by a drop down list in I7).
In row 8 I report the column that the data belongs to in the POST_Data worksheet
What IS working: When I choose an Attendee from the drop down list in C7, I correctly report the first of the Course Names for this attendee from the data in the POST_Data worksheet. I used the following formula to do so: =INDEX(CourseNamesData,MATCH(C7,AttendeeNamesData,0),B$8)
What is NOT working: The corresponding "Date Attended" data when I use a similar formula as the one that is working. I have: =INDEX(DateAttendedData,MATCH(C7,AttendeeNamesData,0),C$8) but this gives me the #REF! error.
Again, when I try to follow the data that this formula points to, it looks like it is pointing to the correct cell but not showing the result.
Another issue is how to get all the data corresponding to the choice in the drop down and not just the first row. So for example, if I choose Richards, K. from the attendee list and he has attended 4 training courses, I need all 4 to show up, not just the first one.
I appreciate any help or insights on this. If you know of a better way to display the workbook contents, please let me know.
Thanks!
Can you provide a screenshot so that I can better understand the issue?
With regard to your post_data worksheet, you might find it easier to turn the data into a table. You can then point your named range to the column within the table without needing to use the offset function, and your range will update automatically as you add to the table.
I have a entire playlist on my youtube channel devoted to using ranges and tables if you are interested. https://www.youtube.com/playlist?list=PL1nLTDk2QLL9415OPSjIICJs1EeV-HeK3