I need to dynamically set the print area of a sheet (Sheet1!). Sheet1 is a summery sheet listing the content of multiple other sheets through an array formula, with content in col A:C. the number of rows are always different, so in order to have the print area height dynamically set to be according to the visible data, i entered a new name in Name Manager with this formula =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$C:$C),3) named DynPrint. and the actual Print Area for Sheet1 I referred to =DynPrint. this should work, but the problem is that excel sees the array formula as content and therefor I'm getting 2000 rows printed out unless i'm manually resetting the print area before each print.
Thank You
Related
So I've created a graph to appear on this separate sheet titled "Report", and above it you can see that there are two dropdown boxes in which a user can select a specific date range. I would essentially like to link this user-specified date range to the range displayed on the graph. I'm having trouble figuring out how to link the source data for the chart to the date selectors.
The data for the chart is sourced from this separate sheet titled "Database", in which the data is chronologically ordered with corresponding Feed values. The goal is to match the dates selected by the user in the "Report" section to the dates in this "Database" sheet, and after finding the corresponding initial and start date, apply that same logic to the feed data to strictly display the feed data within that date range.
I am currently sourcing the chart data using this Macro, the xData and yData are linked to lists titled "Dates" and "FeedTonnage", which are basically tables I made out of the columns in the database. I'm not sure if the tables are even needed, but the database will continue to be updated overtime as more data will be coming in so I thought a table would've been useful for this.
So I've been trying to write a sub that sifts through the Date column to look for a date that matches the dates selected in the "Report" sheet. I'm doing this because I intend on using the cell address to get the corresponding data from the Feed column by replacing the column portion of the cell address with that of the Feed, and yeah, I'm kinda lost at this point so I could really use some input.
Instead of changing the data range of the chart, you can hide the rows of data outside the selected dates:
Worksheets("Database").Rows("3:100").Hidden = False
For i = 3 To 100
If Worksheets("Database").Range("A" & i).Value < Worksheets("Report").Range("B1").Value Or Worksheets("Database").Range("A" & i).Value > Worksheets("Report").Range("C1").Value Then
Worksheets("Database").Rows(i).Hidden = True
End If
Next i
The code above assumes the dates are in the range A3:A100, the start date is in B1 and the end date is in C1. Adjust the ranges as needed
Summary tab:
Source tab:
I'm having some trouble using index match combo and getting the data to reference correctly.
what I am trying to achieve is in a tab called "Summary" I have a calendar with range D5:O6. the first cell in the calendar should change everyday to reflect the current date which will change the rest of the row making a rolling calendar. I have a data reference sheet called "PFS" from which the data needs to be referenced.
The thing I'm having trouble with is that with the formula
=INDEX(PFS, MATCH(A8,Snames,0),MATCH(D5,Sdates,0))
is returning the top left intersection (B8 of the source tab) of A8 and D5 values smith, bob & 4-Aug. a cell that i have entered the value "Wrong Corner".
Snames A8:A9, Sdates D5:O5 are the rows and columns containing the dates and names from the Summary tab
what I need help with is why its returning the wrong intersection and what I can do different to get the data I'm looking for.
The correct return would be the number one, which I have conditionally formatted to turn the cell blue and blank the text
You don't show what PFS references to. It seems to start in A1.
You can either use a range that starts in the correct cell, or add the required offset to the Match results.
=INDEX(PFS, MATCH(A8,Snames,0)+2,MATCH(D5,Sdates,0)+2)
Also make sure that Sname and Sdates refer to the ranges in the Source tab, not the Summary tab.
I have this bar chart in excel :
As you see, if there is #'¡DIV/0!, the values are 0. What I really want is that the bar chart just shows the numeric values. In this case. just the first three values would have to be visualized. I tried the formula IF.ERROR(FORMULA,"") but the result was the same,
So, How Can I do that?
You need dynamic ranges for the chart, or filter the data source to hide the rows with the error. Excel charts will not include data that is hidden with a filter.
To apply dynamic ranges, create two range names with the following formulas:
chtLabels =OFFSET(chtValues,0,-1)
chtValues =Sheet1!$B$12:INDEX(Sheet1!$B:$B,MATCH(99^99,Sheet1!$B:$B,1))
Adjust the chtValues range name to start in the first cell with a number in column B instead of B12 of the example.
Edit the column chart series values and enter the range name, preceded by the sheet name, like
=Sheet1!chtValues
Edit the Horizontal axis labels and replace the range with the dynamic named range
=Sheet1!chtLabels
When you exit the dialog, Excel will replace the sheet name with the file name. The result will be similar to this:
Note how the series formula shows the range names instead of the cell ranges.
=IFERROR(value, value_if_error) where value_if_error should equal 0 or "" or whatever you want
I have a dynamic hyperlink that selects the last cell in a specified column within a sheet, regardless of th number of items in that column. So if I have 22 items in a column, the link will select the 23rd row, etc.
What I am trying to do is have it select the last cell (in the same fashion), but within a different sheet of the same workbook - provided that my reference cell is set to the appropriate number (i.e. I have a dropdown selector which sets the value of this reference cell and that changes the hyperlink.
I implemented this using an IF and a COUNTA statement, but I can't figure out how to make the link formula count the number of items in columns of different sheets. Here's the function:
=IF(J6=1, HYPERLINK("#Parts!b"&COUNTA(B:B)+3, "Add New Entry"), HYPERLINK("#Employees!b"&COUNTA(B:B)+3, "Add New Entry"))
How do I change the formula so that the COUNTA is executed in the appropriate worksheet?
Just add your sheet name! in front of the column range you've defined in counta(). For instance if your sheet's name is sheet1 you would do the following:
=IF(J6=1, HYPERLINK("#Parts!b"&COUNTA(sheet1!B:B)+3, "Add New Entry"), HYPERLINK("#Employees!b"&COUNTA(sheet1!B:B)+3, "Add New Entry"))
I've got a spreadsheet with plenty of graphs in it and one sheet with loads of data feeding those graphs.
I've plotted the data on each graph using
=Sheet1!$C5:$C$3000
This basically just plots the values in C5 to C3000 on a graph.
Regularly though I just want to look at a subset of the data i.e. I might just want to look at the first 1000 rows for example. Currently to do this I have to modify the formula in each of my graphs which takes time.
Would you know a way to simplify this? Ideally if I could just have a cell on single sheet that it reads in the row number from and plots all the graphs from C5 to C 'row number' would be best.
Any help would be much appreciated.
OK, I had to do a little more research, here's how to make it work,
completely within the spreadsheet (without VBA):
Using A1 as the end of your desired range,
and the chart being on the same sheet as the data:
Name the first cell of the data (C5) as a named range, say TESTRANGE.
Created a named range MYDATA as the following formula:
=OFFSET(TESTRANGE, 0, 0, Sheet1!$A$1, 1)
Now, go to the SERIES tab of the chart SOURCE DATA dialog,
and change your VALUES statement to:
=Sheet1!MYDATA
Now everytime you change the A1 cell value, it'll change the chart.
Thanks to Robert Mearns for catching the flaws in my previous answer.
This can be achieved in two steps:
Create a dynamic named range
Add some VBA code to update the charts data source to the named range
Create a dynamic named Range
Enter the number of rows in your data range into a cell on your data sheet.
Create a named range on your data sheet (Insert - Name - Define) called MyRange that has a formula similar this:
=OFFSET(Sheet1!$A$1,0,0,Sheet1!$D$1,3)
Update the formula to match your layout
Sheet1!$A$1 set this to the top left hand side of your data range
Sheet1!$D$1 set this to the cell containing the number of rows
3 set this value to the number of columns
Test that the named range is working:
Select the dropdown menus Edit - Go To, type MyRange into the reference field.
Your data area for the chart should be selected.
Add some VBA code
Open the VBA IDE (Alt-F11)
Select Sheet1 in the VBAProject window and insert this code
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$D$1" Then Exit Sub
'Change $D$1 to the cell where you have entered the number of rows
'When the sheet changes, code checks to see if the cell $D$1 has changed
ThisWorkbook.Sheets("Sheet1").ChartObjects(1).Chart.SetSourceData _
Source:=ThisWorkbook.Sheets("Sheet1").Range("MyRange")
' ThisWorkbook.Sheets("Chart1").SetSourceData _
Source:=ThisWorkbook.Sheets("Sheet1").Range("MyRange")
'The first line of code assumes that chart is embedded into Sheet1
'The second line assumes that the chart is in its own chart sheet
'Uncomment and change as required
'Add more code here to update all the other charts
End Sub
Things to watch for
Do not directly use the named range as the data source for the chart. If you enter the named range "MyRange" as the Source Data - Data Range for the chart, Excel will automatically convert the named range into an actual range. Any future changes to your named range will therefore not update your chart.
Performance might be impacted by the approaches listed above.
The OFFSET function in the named range is "volatile" which means that it recalculates whenever any cell in the workbook calculates. If performance is an issue, replace it with the INDEX formula.
=Sheet1!$A$1:INDEX(Sheet1!$1:$65536,Sheet1!$D$1,2)
The code fires everytime data is changed on Sheet1. If performance is an issue, change the code to run only when requested (i.e. via a button or menu).
You could look at dynamic ranges. If you use the OFFSET function, you can specify a starting cell and the number of rows and columns to select. This site has some useful information about assigning a name to an OFFSET range.
You can set the range for a chart dynamically in Excel. You can use something like the following VBA code to do it:
Private Sub Worksheet_Change(ByVal Target as Range)
Select Case Target
Case Cells(14, 2)
Sheet1.ChartObjects(1).Chart.SetSourceData Range("$C5:$C$" & Cells(14,2))
...
End Select
End Sub
In this case, the cell containing the number of the last row to include is B14 (remember row first when referring to the Cells object). You could also use a variable instead of the Cells reference if you wanted to do this entirely in code. (This works in both 2007 and 2003.) You can assign this procedure to a button and click it to refresh your chart once you update the cell containing the last row.
However, this may not be precisely what you want to do ... I am not aware of a way to use a formula directly within a chart to specify source data.
Edit: And as PConroy points out in a comment, you could put this code in the Change event for that worksheet, so that neither a button nor a key combination is necessary to run the code. You can also add code so that it updates each chart only when the matching cell is edited.
I've updated the example above to reflect this.
+1s for the name solution.
Note that names don't really really reference ranges, they reference formulae. That's why you can set a name to something like "=OFFSET(...)" or "=COUNT(...)". You can create named constants, just make the name reference something like "=42".
Named formulae and array formulae are the two worksheet techniques that I find myself applying to not-quite-power-user worksheets over and over again.
An easy way to do this is to just hide the rows/columns you don't want included - when you go to the graph it automatically excludes the hidden rows/columns
Enhancing the answer of #Robert Mearns, here's how to use dynamic cells ranges for graphs using only the Excel's formulas (no VBA required):
Create a dynamic named Range
Say you have 3 columns like:
A5 | Time | Data1 | Data2 |
A6 | 00:00 | 123123 | 234234 |
...
A3000 | 16:54 | 678678 | 987987 |
Now, the range of your data may change according to the data you may have, like you have 20 rows of data, 3000 rows of data or even 25000 rows of data. You want to have a graph that will be updated automatically without the need to re-set the range of your data every time you update the data itself.
Here's how to do it simply:
Define another cell that it's value will have the number of the occupied cells with data, and put the formula =COUNTIF(A:A,"<>"&"") in it. For example, this will be in cell D1.
Go to "Formulas" tab -> "Define Name" to define a name range.
In the "New Name" window:
i. Give your data range a name, like DataRange for example.
ii. In the "Refers to" set the formula to: =OFFSET(Sheet1!$A$1, 0, 0,Sheet1!$D$1,3),
where:
Sheet1!$A$1 => Reference: is the Reference from which you want to base the offset.
0 => Rows: is the number of rows, up or down, that you want the upper-left cell of the results to refer to.
0 => Columns: is the number of columns, to the left or right, that you want the upper-left cell of the results to refer to.
Sheet1!$D$1 => Height: is the height, in number of rows, that you want the result to be.
3 => Width: is the width, in number of columns, that you want the result to be.
Add a Graph, and in the "Select Data Source" window, in the Chart data range, insert the formula as you created. For the example: =Sheet1!DataRange
The Cons: If you directly use the named range as the data source for the chart, Excel will automatically convert the named range into an actual range. Any future changes to your named range will therefore not update your chart.
For that you need to edit the chart and re-set the range to =Sheet1!DataRange every time. This may not be so usable, but it's better than editing the range manually...