office scripts
490 TopicsSeries fill a formula down a column automatically skipping a set number of rows
I am trying to fill a formula down a column every 6th row but incrementing the variable in the formula ($A2) for each entry. The formula uses the Take command and inputs 5 rows of data, so to keep it from "spilling" I need the formula to increment every 6 rows, having one blank row between each section. I have been able to accomplish "copying" it each 6th row with VBA #1 and filling the series with VBA #2 but can't figure out how to combine the two. Any help would be appreciated. VBA #1: Sub FillEvery6thCell() Dim ws As Worksheet Dim startRow As Long, lastRow As Long, col As String Dim formulaText As String Dim r As Long ' Set your sheet and parameters Set ws = ThisWorkbook.Sheets("Top 5 Employees") col = "A" ' Column to fill startRow = 10 ' First row to start filling lastRow = 60000 ' Last row to fill ' Get the formula from the starting cell formulaText = ws.Range(col & startRow).Formula ' Fill every 6th cell For r = startRow + 6 To lastRow Step 6 ws.Range(col & r).Formula = formulaText Next r Range("A2:A60000" & iRow).Replace What:="@", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2 MsgBox "Formula copied to every 6th cell in column " & col End Sub VBA #2 Sub FillFormulasDown() Dim sourceCell As Range Dim fillRange As Range ' Define the cell containing the formula Set sourceCell = Range("A2") ' Define the target range Set fillRange = Range("A2:A5000") ' Fill formulas down sourceCell.AutoFill Destination:=fillRange, Type:=xlFillSeries End Sub132Views0likes6CommentsOffice Script - Bug in .map()?
Hi, I'm pretty sure this is a bug, but maybe I'm doing something silly when constructing the formula? I'm trying to set formulas down a column in a table, from an array called test1. The test1 array is created using .map() from an original array (file_names) that uses .getTexts from another column in the same table. The dimensions of target_range (another column in the same table) match those of test1 array. The test1 array is appropriately 2D (i.e. [[formula1],[formula2]...[formulaN]]. The test1 array is correct when inspected in console.log() (in all cases, including when an equals sign is used.....explained more below). The problem is that trying to use .setFormulas, is only using the first value from test1 for every cell in target_range, not each respective element from test1. After a massively frustrating amount of time, I've traced the problem solely to this (as far as I can tell): The presence of an equals sign in the .map() when using string interpolation to create the formula. This code correctly writes the text of the formula into each cell of target_range, using each respective value from write_array with appropriate interpolation: let file_names: string[][] = rng_file_names.getTexts(); let test1: string[][] = file_names.map( row => [`\"${row}\"&\"TestString\"`] ); target_range.setFormulas(test1); If you try to do exactly the same, but try turning it into a formula by including the equals sign at the start of the interpolated string inside the array returned by the .map(), it will only write the first value of test1 into all cells of target_range: let file_names: string[][] = rng_file_names.getTexts(); let test1: string[][] = file_names.map( row => [`=\"${row}\"&\"TestString\"`] ); target_range.setFormulas(test1); I'm pretty sure this is a bug, but if someone can point if I'm doing something stupid, it would be appreciated!55Views0likes1CommentFilling a column with succeeding lists
Hi, I need a list of files, with numbers starting from 001 for each box. Adding the number for one box is easy but I have thousands of them. A box number is like "0001AA0001". The first number and the letters never change, so I have : 0001AA0001 0001AA0002 0001AA0003 Then I have to add the files numbers, like "0001AA0001/001". I already have a line for each file, but only with the box number in the forst column, repeated several times, each time for every file. What I have What I need 0001AA0001 0001AA0001/001 0001AA0001 0001AA0001/002 0001AA0001 0001AA0001/003 0001AA0002 0001AA0002/001 0001AA0002 0001AA0002/002 0001AA0003 0001AA0003/001 0001AA0004 0001AA0004/001 0001AA0004 0001AA0004/002 0001AA0004 0001AA0004/003 Can you please tell me how can I add automatically the /001 and so on without having to do it for each box ? I can't manage to use a model for CTRL+E and I'm not accustomed to use the functions. Thanks, M.T.158Views0likes3CommentsTokyo Stock Exchange data
Does any one know, and can share, a sample excel file that can import updated information (ticker, name, last price, dividend yield, daily high and daily low and analysts average target price) for ~50 stocks traded on the Tokyo stock exchange, which is not covered by Microsoft?358Views0likes3CommentsHelp needed with IF and COUNTIFS Formulas
Is anyone able to advise the following formula: =COUNTIFS($B$5:$B$15,$R$4,$C5:$C15,"<=" & V3,$D5:$D15, ">" & V3)-COUNTIFS($B$5:$B$15,"="&$R$4,$G5:$G15,"<=" & V3,$H5:$H15, ">" & V3)-COUNTIFS($B$5:$B$15,"="&$R$4,$K5:$K15,"<=" & V3,$L5:$L15, ">" & V3)-COUNTIFS($B$5:$B$15,"="&$R$4,$O5:$O15,"<=" & V3,$P5:$P15, ">" & V3) Is there a way to simplify this? Is there a way to make this more accurate? Cells in column G & H, I & J, O & P are using the following format: =IF(C6="","",C6+E6) Cells in U4:CC4 are using the following format: =COUNTIFS($B$5:$B$15,$R$4,$C5:$C15,"<=" & U3,$D5:$D15, ">" & U3)-COUNTIFS($B$5:$B$15,"="&$R$4,$G5:$G15,"<=" & U3,$H5:$H15, ">" & U3)-COUNTIFS($B$5:$B$15,"="&$R$4,$K5:$K15,"<=" & U3,$L5:$L15, ">" & U3)-COUNTIFS($B$5:$B$15,"="&$R$4,$O5:$O15,"<=" & U3,$P5:$P15, ">" & U3) Cells in U5:CC15 are using the following format: =IF(U$4>=$T5,1,"") My issue is is when I put in the three break times, the mid break comes out at a shorter time. My other issue is is that when I put in the times in row 5,6and 11, the data is coming up as a combined data in rows 5, 6 and seven on the page two. Just for reference, "page two" is the same spreadsheet. What I need to happen is that I enter in the shift start time and finish time. This then populates through to Break 1, 2 and 3. The Time entry is the time the break starts. ie: 1 hour after start of shift, 1 hour after coming back from break, etc. The break entry is the duration of the break taken. ie: 30 minutes. Once all the info is put in, the relevant "Time Block" on "Page 2" shows a 1. What is happening at the moment is that when I enter all the time data, the time blocks are not populating correctly in accordance to the entry. Basically, If I have numerous people on shiftI need the time blocks to show where I have shortfalls in shift cover and not having too many people on break at the same time. IE: Link to Live Copy: https://www.dropbox.com/scl/fi/eur1j526htu1j8a4d4290/Staff-Breaks.xlsx?rlkey=r4tm9xts4tonofpa2th2cusfw&st=nueyk0d7&dl=0 Any ideas would be greatly appreciated.262Views0likes4CommentsDisappearing Script Button
In the online version of excel, I have a script button keeps disappearing. This same button is fine on desktop and I don't believe this was a problem before. When I load the page it isn't there. I found that if I added another button on another sheet in that workbook, that when I switch to that sheet and then I return to the first sheet the button returns, but if I refresh the page again, the button disappears. If I switch to a tab without a script button then the button does not return. i have tried minimizing the browser, changing zoom levels, scrolling and such but the only thing I have found to make the button re-appear is switching to another sheet that has a script button on it (I created a 'dummy button' on that sheet). I don't know why this button that I need disappears while that 'dummy' button I put on the other tab doesn't disappear and I don't know why having that other button makes it reappear by just switching to that tab and back. a) has anyone else experienced any problem like this? b) does anyone have any ideas to try or why it is happening? thank you.Solved392Views0likes4CommentsMoving a column of text data into 3 columns of data?
I have a column of text data cells 1,2,3,4,5,6,7,8,9 and longer. I want to create 3 column of data to graph and manipulate Cell in Columns. 1,2,3 3,4,5 5,6,7 8,9,10 and longer. So i need to create 3 columns of data from 1 column of data. I am using Mac Excel 16 and I can not make this happen. I have tried all sorts of solutions. Help? Thank you,247Views0likes3CommentsUnprotect in Office Scripts
I am writing an office script that requires sorting on a sheet with the overall sheet protected and specific cells not protected. I need to be able to sort an unprotected range using an automation but the protection is restricting it even though I have "sort" allowed in the protection options. Is there a way to unprotect and then re-protect the sheet as part of the scripts? Including passwords? function main(workbook: ExcelScript.Workbook) { let selectedSheet = workbook.getActiveWorksheet(); // Clear auto filter on selectedSheet selectedSheet.getAutoFilter().clearCriteria(); // Custom sort on range range C9:I6001 on selectedSheet selectedSheet.getRange("C9:I6001").getSort().apply([{key: 0, ascending: true}], false, true, ExcelScript.SortOrientation.rows); // Apply values filter on selectedSheet selectedSheet.getAutoFilter().apply(selectedSheet.getAutoFilter().getRange(), 6, { filterOn: ExcelScript.FilterOn.values, values: ["1"] }); }159Views0likes1Comment