I have 100s of pages of data that I need to print and I want to have a header and a side column on every Page that is printed.
I can do this manually by using the dynamic range that I have created but I have to manually enter the name of the range into the page layout settings. I also tried to use a macro to do this using my dynamic ranges but I get an error message when I run the following script;
Sheets("1. Paste Raw Data").Select
ActiveSheet.PageSetup.PrintTitleColumns = Sheets("1. Paste Raw Data").Range("Print_Side")
ActiveSheet.PageSetup.PrintTitleRows = Sheets("1. Paste Raw Data").Range("Print_Header")
I have also tried to use the range that is defined by excel (named Print_Titles) to change these settings when the pages are printed but it will not allow me to enter more than one dynamic range. Print_Titles is currently defined like this in name manager;
='1. Paste Raw Data'!$B:$B,'1. Paste Raw Data'!$4:$6
Is there a way of using the two dynamic ranges in to define the titles for the rows and the columns?
I am afraid what you are trying to do, is not accepted by Excel...
It allows setting of PrintTitleRows like Rows, not like a range (like your dynamic range). Excel allows setting only of the ROWSto be repeated. In case of using a range (manually selected), Excel extends the range, to include full rows. In terms of range, it accepts only a range of rows.
If you insist to use your dynamic range you can use:
ActiveSheet.PageSetup.PrintTitleRows = _
ActiveSheet.Rows(Names("Print_Header").RefersToRange.Row).Address
but it would be like you scratch your left side of your head using the right arm...
You can also proceed similarly for PrintTitleColumns, but you will obtain the same result just using of:
ActiveSheet.PageSetup.PrintTitleColumns = "$A:$A"
Even you would manually try setting of those parameters, you would observe that Excel does not allow selecting of ranges. It extends the selection to the whole row(s) or column(s) according to the setting specificity.
Related
I have a excel document that has several name ranges that are currently save to static web pages. I have recently tried to conver them to dynamic ranges, and have learned the dynamic named ranges work great within the context of the excel sheet itself, but fail once excel tries to save them as the static web page.
For example, I have a range
YardTabletLists!$EC$1:$EE$101
sometimes the content is exceeds the bounds or I have empty rows on my webpage.
the dynamic alternative is
=OFFSET(YardTabletLists!$EC$1,0,0,COUNTA(YardTabletLists!$EC$1:$EC$10000)+1,3)
If i refernce this name range anywhere within the sheet, it works, but when AutoPublish does it thing, I get the following error.
Error Notice
I was thinking of trying to conver the Dynamic range back to a static range somehow, and then direct the name rage to that Cell.... i.e.
Name range is directed to =E4, and E4 contains YardTabletLists!$EC$1:$EE$101, but I get the feeling that will give me the same issue.
Thanks to those who read this.
Not familiar with static webpage feature.
But possible to define and use “table” instead of “named range”?
With “table” Excel internally handles the correct range whenever the table size is modified.
Seems the static webpage feature supports also “filtered ranges”. Could this be a work-around, e.g. to filter out blank lines (while using max line number as static range)?
Indirect references (your example with E4) are a little tricky in Excel. I only used it once to define a list for a dropdown.
Muss be supported by the feature and requires “special” syntax
Update:
I have found some examples for VBA updating name ranges, and one excellent example that appears to answer the question:
https://excelchamps.com/vba/named-range/#Resizing_a_Named_Range_using_VBA_Dynamic_Named_Range
Sub vba_named_range()
Dim iRow As Long
Dim iColumn As Long
iRow = ActiveSheet.Range("A1").End(xlDown).Row
iColumn = ActiveSheet.Range("A1").End(xlToRight).Column
ActiveSheet.Range("myRange") _
.Resize(iRow, iColumn).Name = "myRange"
End Sub
for some reason the program hangs up at
ActiveSheet.Range("myRange") _
.Resize(iRow, iColumn).Name = "myRange"
does anyone see perhaps a syntax error I am missing?
Thank you :)
I'm working a subroutine which does filtering via hiding rows/cols. I realized that the end user if they copy data, will copy the hidden rows.
I'd like to just have my routine finish by having those cells selected, but I tried used rng.select(); w/ both visibleview and specialcells but both error saying select isn't approriate for that object.
var usedrng = ws.getUsedRange(true).getSpecialCells("Visible");
var usedrng = ws.getUsedRange(true).getVisibleView()
I'm resorting to coping the data to a new worksheet, but wondered if there was a way because I saw this quote:
Non-continuous selections are not only not supported in Office.js (for
Word, we DO support them for Excel though)
Update: I found a workaround that I'm happy with, but I'll leave question as my workaround requires turning on filtering which may not be desired. In my case, I wasn't filtering due to needing multiple criteria's more then filter can handle.
My workaround is to use my normal function to hide rows. Then grab getVisibleView and push filter column values to Array. I then unhide rows and apply a filter on values with that array of items.
You can then use getUsedRange(true) and select. When I used CTRL + C only the visible cells were selected as per normal filtering copy/paste SOP. This enables me not to have to copy data to a new WS and leave the existing WS active.
I'm trying to get some details copied in Excel from Sheet 1 columns 1-5 to Sheet 2 columns 1-4, but only for lines that include text or values on sheet one under a specific column (in this case, Column 2). There are other columns in between, so I need to be able to use exact columns rather than A:D for example.
Example of what I'm trying to achieve:
I have tried using a simple IF function with A:A<>"" so it would include any rows that have any data in them, however this does not seem to copy as I need and occasionally based on my attempts i also get circular reference errors. Additionally, I’m not sure how to make sure this gets pasted at the bottom of a table that will expand with each addition.
I realize a probably easier option would be to simply copy Sheet 1 entirely and use a filter on row 1 to deselect Blanks on A:A, but the sheet has so much more info that it would be a waste, and additionally info is constantly added so I need something scale-able. It also occurred to me now that by doing this i would include info from the "header" and "footer", basically a frozen pane - which I do not need.
Could this be done via a simple function, or would it require a Macro?
Please keep in mind I'm rubbish at programming, just trying to make my life easier and learn as I go. A lot of excel forums help but still I'm no coder. I can understand to a pretty big degree what the code does and can adjust accordingly though :)
As suggested, this cannot be done with formulas. There are different ways to achieve this.. below is one approach:
Sub CopyFilteredRows()
Dim oSourceSheet As Worksheet: Set oSourceSheet = ThisWorkbook.Worksheets("Sheet3") ' Set your source sheet here
Dim oRng As Range: Set oRng = oSourceSheet.Range("A2:E" & oSourceSheet.Range("C" & oSourceSheet.Rows.Count).End(xlUp).Row)
' Set filter on column B
oRng.AutoFilter
oRng.AutoFilter 2, "<>"
' Copy to specified sheet
oRng.SpecialCells(xlCellTypeVisible).EntireRow.Copy ThisWorkbook.Worksheets("Sheet4").Range("A2") ' Change your destination sheet here
' Clear objects
Set oRng = Nothing
Set oSourceSheet = Nothing
End Sub
Paste the above UDF in a Module and then run it whenever you want to perform the copy. I suspect you would have to modify it a bit so that you can cater for your particular scenario but it should give you a start
So, I've created a dynamic range for a chart, that's all well and easy.
However, in this chart there are two lines, but I only want one of the lines to show up under certain conditions, else it displays nothing! So I've tried creating my dynamic range as follows
=IF('WorksheetName'!$M$10 ='WorksheetName'!$F$31,'WorkSheetName'!dynamic_range, #N/A)
The problem is that when I do this the chart freaks out. It gives me this error:
Your formula contains an invalid external reference to a worksheet.
Verify that the path, workbook, and range name or cell reference are
correct, and try again.
If I click "ok" half the time it shows up correctly (that is, the second line disappears and the chart adjusts accordingly) and the other half the time it glitches.
Basically, how do I create a dynamic range for graphing that the chart will understand when I want it to do NOTHING and when I want it to display the range?
You need a second source range, that's cells are just empty. Applying your approach to switch between the filled range (intended to be visible) vs. the empty range (will be invisible), shall solve the issue. Note: The chart parameter "Show empty cells as:" should be set to "Gaps". (Refer to the Hidden and Empty Cells options in the chart's Select Data dialog. This is applicable to X/Y charts mainly.)
I am creating a form in excel (not a userform) and I am populating the listbox using cells. However, these cells are sometimes A1:10 and sometimes they are A1:A4. Is there a way to dynamically change what is shown in the listbox?
Right now, when I use A1:10 and there are only 4 cells populated, I get the list of 4 populated cells followed by 6 blank entries. I'd like to get rid of the 6 blanks when there are only 4.
Unfortunately, this is more of a workaround than a solution. However, it may be able to do what you need it to do. I've been hitting the same wall you are with trying to make ranges dynamic.
Without seeing some code to know exactly what you're doing, try something like this.
Private Sub ListBox1()
x = 1
'Add items to listbox until you reach an empty cell.
Do while Cells(x,1) <> ""
ListBox1.AddItem Cells(x,1)
Loop
I'm not very familiar with listboxes outside of userforms but this should do approximately what you want to do.
Edit your original post with your code so we can try and get a better understanding of what you've tried and what you're trying to do.
You can create a named range using a dynamic formula. Either of the below formulas will work.
=A1:INDEX($A$1:$A$10,MATCH("",$A$1:$A$10,0)-1)
=OFFSET($J$7,0,0,MATCH("",$J$7:$J$32,0)-1)
To create the named range, click ctrl+F3 then click new, insert one of the two options above into the "refers to:" section, then label the new range whatever you would like. in the "row source" section of the listbox simply type in the name you selected for your new named range.