VBA Help to Copy Worksheet from Excel into Word - excel

I am creating a service contract for a client. The document has an Appendix that is a table that changes depending on the product. All of the Appendix tables are in Excel, and I have created an INDEX MATCH function to return the name of a Named Range according to the product chosen, and now I need Excel to actually display that range.
This is my function:
=INDEX(References,MATCH(A2,Reference!A2:A30,0),MATCH(B2,Reference!B1:D1,0))
It returns a Named Range because that's the data I have in the table:
"References", but I want it to display the table and not just its name.
My ultimate goal is to have Word display the correct table depending on choices selected in form fields within the contract. Basically, I want to automate copying the correct table from Excel into Word. It needs to keep its original formatting. Pasting as an object or image is acceptable.

Related

Create new table in Excel worksheet from filtered values of a table, or pull filtered set of data from Graph API or Power Automate

I am trying to create a table in a worksheet based on a filtered set of results from an existing table in another worksheet. I have the initial table in a worksheet entitled "Form1", and have created a second worksheet with the following formula in cell A1.
=FILTER(Form1!A:G,(Form1!C:C>=(TODAY()-1+12/24)),"No matches")
This formula works to display the results I am looking for, but not as a table. I need this to be a table so I can pull it via the Graph API or Power Automate. I have not worked much with Excel so I am sorry if there is already a solution to this and I am just not searching for the correct terms. Is there a way to accomplish what I need to do, either by making this a table or some other means using the Graph API or Power Automate?
Note that I can't just pull the data directly from the initial table and filter based on that, as this table contains 13K+ entries. This filtered data set will always contain less than 50 entries.

Select Data for excel Graph sees zeroes when I load the data using sql

I have a problem with Excel (2016)/ VBA macros. I am happy to provide more detail or copies of files if required.
In summary this is what is happening:
I have a workbook with five worksheets. Three contain data representing both axes of a matrix (1&2), the cells of the matrix (3), one sheet on which data from sheets 1 to 3 are brought together (4) and - finally - a graph worksheet (5 - based on a range in 4).
The reason I do it like this is that I want to graph parts of the data at a time otherwise it is all too confusing. A simple form is used to choose which column of the data-set to display and to also allow stepping through the list of items to display so just part of the range is in view at a time. Variables are set in cells on sheet 4 (outside the graphed range) when the buttons are clicked on the form. The formulae that populate the graphed range on that sheet use these variables to choose the required data from sheets 1 to 3.
Initially I populated the data in sheets 1 to 3 using macros to read from text files. These files had to be populated from a database before opening the Excel workbook. I decided to "Simplify" this process by changing the macros to query the database directly.
It took a while to get this going and all looked fine. I can see the data in the first four worksheets is populated correctly (including being able to click on the form buttons and change the contents of the graphing range) but the graph sees values of zero in every cell. When I right click on the graph and select "Select Data" and then choose an item in the "Legend Entries (Series)" list in the left-hand box, and the click "Edit", I see the cell ranges of both the Series name and the Series Values are correctly displayed, the preview of "Name" has the correct value but the preview of "Series" shows a string of comma-separated zeroes.
I can switch worksheets to view the "GraphData" on sheet 4 while still keeping the dialogue box open and see the actual cells that are being referred to and they are not 0, 0, 0... they are 78, 69, 44...
Where are the zeroes coming from?
I have even saved the workbook - keeping changes - so the contents of sheets 1 to 3 are kept, put a stop in the "Workbook_Open" macro so it doesn't run, and still I get zeroes when I re-open it.
Sorry to bother folk. I worked out the problem. As usual, there were interesting lessons along the way.
I started out with a query that populated a text file with data from my database. Because I wanted the file to be ingested by Excel as a csv file, the output for each row of the selected data was a single string column containing the keys and the data values with commas between them, the numbers being converted to VARCHAR within the sql so I could concatenate them into the string.
Them when I decided to try using the query directly from Excel rather than having the file step in between, I removed the concatenation operators and the commas and put a comma between them in the sql syntax but didn't remove the conversion to VARCHAR of the numbers.
With QueryTable, when you import a text file, one of the optional properties is an array of codes representing the data types of the incoming data. I assumed that with a direct query, Excel would assign a data type based on content as it does for typed values (unless you specify another). Clearly Excel and the source database exchange information, in addition to the data set itself, that tells Excel the data type of the columns - as sent.
The graphing function was seeing my data as strings so assigned values of zero. I began by putting a Value() around my lookup functions on the GraphData worksheet. That worked but then I went further back and actually changed the Sql so it sent numeric data without conversion to VARCHAR and then it worked without the Value() change.
It never occurred to me that Excel wouldn't just see a number and treat it as such - not that Sql Server would have told Excel it was a string.

Using VBA in Excel to automatically update chart data

I currently am importing data into Excel. This data changes from time to time. I am trying to determine if there is a way to automatically update the data source range.
I would define a name in the file with the data source range by going to Formulas -> Define Name. There you can set a name to be a formula that dynamically updates
=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),COUNTA(Sheet1!1:1))
This selects a table based on a count of how many values are in Column A and Row 1.

Change sheet source dynamically

How to change Excel sheet source dynamically depending on particular values?
I am developing an Excel sheet. Depending on one dropdown value, fields of other dropdown should change dynamically.
Suppose I choose one value from dropdown1, dropdown2 should get certain column from "Sheet2" and if I choose another value from dropdown1, dropdown2 should get certain column from suppose "Sheet".
How can I achieve this?
This should be related to Excel formulas I guess.
Just follow this tutorial
Create lists
Give lists a name
Use data validation to create dropdown
Use indirect when creating new data validation

dynamic linking of word and excel

This is my first question and it would have been nice to include an image but it seems that I can't. I have seen some answers to my problem but they always seen to be in one direction. Excel->Word. However I want Word->Excel->Word as described below.
I have an excel workbook that draws a graph. Some of the input data is pre-calculated and one or two parameters are entered manually and entered in a table in the spreadsheet.
I want to do the following.
The graph and the data entry table are to be displayed in word. The table in Word is also part of the spreadsheet but must be displayed separately. I want to be able to enter the variables in the table in the word document. These values are linked to the excel sheet, the graph will be changed and the actualised version displayed in the word document. I have attached two images, the data entry able. The entry fields are those in green and an image of the resulting graph. Any help would be appreciated.
I can't see your pictures, so the following is theoretical.
1) Open Word
2) Insert Chart - this opens a instance of Excel which is directly linked to the Chart, which I'll refer to as ExcelChartData to avoid confusion.
3) Edit the range in ExcelChartData to match what you have in your Excel data workbook.
4) Link the ranges in ExcelChartData to the required ranges in your Excel data workbook.
Changing the values in your Excel data workbook will then change the chart.

Resources