range

Row count where data exists

雨燕双飞 提交于 2019-12-03 14:02:16
I need to count the total number of rows that have data. I want to be able to use this on multiple sheets with different amounts of data rows. I cannot figure out generic code that will count the number of rows from A1-A100 or A1-A300. I am trying to use something like this. i = ActiveWorkbook.Worksheets("Sheet1").Range("A2 , Range("A2").End(xlDown)).Rows.Count If you need VBA, you could do something quick like this: Sub Test() With ActiveSheet lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row MsgBox lastRow End With End Sub This will print the number of the last row with data in it. Obviously

How to do an inverse `range`, i.e. create a compact range based on a set of numbers?

时光怂恿深爱的人放手 提交于 2019-12-03 13:29:01
问题 Python has a range method, which allows for stuff like: >>> range(1, 6) [1, 2, 3, 4, 5] What I’m looking for is kind of the opposite: take a list of numbers, and return the start and end. >>> magic([1, 2, 3, 4, 5]) [1, 5] # note: 5, not 6; this differs from `range()` This is easy enough to do for the above example, but is it possible to allow for gaps or multiple ranges as well, returning the range in a PCRE-like string format? Something like this: >>> magic([1, 2, 4, 5]) ['1-2', '4-5'] >>>

Why does the range of int has a minus 1?

此生再无相见时 提交于 2019-12-03 13:25:52
I read that the range of an int is dependent on a byte. So taking int to be 4 bytes long, thats 4 * 8 bits = 32 bits. So the range should be : 2 ^ (32-1) = 2 ^ (31) Why do some people say its 2^31 - 1 though? Thanks! Because the counting starts from 0 And the range of int is 2,147,483,647 and 2^32 which is 2,147,483,648 . hence we subtract 1 Also the loss of 1 bit is for the positive and negative sign Check this interestinf wiki article on Integers:- The most common representation of a positive integer is a string of bits, using the binary numeral system. The order of the memory bytes storing

Filter _id range in elasticsearch

不打扰是莪最后的温柔 提交于 2019-12-03 13:17:13
问题 I am trying to filter _id field (index not enabled) in elasticsearch by range. Is it possible? If so, how it can be done? I've read in elasticsearch documentation that we can use 'ids' to query by _id and type, but I can't see how it can be done with range filter. (I don't want to enable index on _id). { "from": 0, "size": 20, "query": { "match_all": {} }, "filter": { "range": { "_id": { "gt": "51f7b6b7710c42b136027581" } } }, "sort": { "pubdate": { "order": "desc" } } } 回答1: Maybe it's a

How to define dynamic ranges on Calc (or Excel)?

一世执手 提交于 2019-12-03 13:04:27
问题 Let's say I have a Libreoffice.org Calc (maybe this goes for MS Excel too) object defined as the range $Sheet1.$A$1:$A$4 . I also have declared a constant with value 1. For this mockup purpose, let's call it startingLine . Both objects are properly defined in the Define Names dialog (shortcut: Ctrl+F3). What I would like to do is to turn the lines of the defined range into variables. In my mind, all it'd take would be to define it like this: $Sheet1.$A$startingLine:$A$4 , but this doesn't

Given a set of ranges S, and an overlapping range R, find the smallest subset in S that encompases R

爱⌒轻易说出口 提交于 2019-12-03 13:00:50
The following is a practice interview question that was given to me by someone, and I'm not sure what the best solution to this is: Given a set of ranges: (e.g. S = {(1, 4), (30, 40), (20, 91) ,(8, 10), (6, 7), (3, 9), (9, 12), (11, 14)} . And given a target range R (e.g. R = (3, 13) - meaning the range going from 3 to 13). Write an algorithm to find the smallest set of ranges that covers your target range. All of the ranges in the set must overlap in order to be considered as spanning the entire target range. (In this example, the answer would be {(3, 9), (9, 12), (11, 14)} . What is the best

How would you display an array of integers as a set of ranges? (algorithm)

五迷三道 提交于 2019-12-03 12:54:16
Given an array of integers, what is the simplest way to iterate over it and figure out all the ranges it covers? for example, for an array such as: $numbers = array(1,3,4,5,6,8,11,12,14,15,16); The ranges would be: 1,3-6,8,11-12,14-16 If the array is sorted in ascending order, then the problem is easy. Define a Range structure or class, which has a beginning and an end. Then go through the array. If the current element is one more than the previous, update Range.end , otherwise create a new range with this element as Range.begin . Store the ranges to a dynamic array or a linked list. Or just

How is irange() any different from range() or xrange()?

我的梦境 提交于 2019-12-03 12:36:26
问题 I was going through Python Generators Wiki when I came across this RangeGenerator page which talks about irange() - This will let us iterator over large spans of numbers without resorting to xrange, which is a lazy list as opposed to a generator. I can't seem to understand the test suite and the implementation described on that page. I know that range() creates a list in the memory (from Python 2.7 point of view) and xrange() is a generator. How is irange() any different? 回答1: irange()

Replace specific word in contenteditable

旧街凉风 提交于 2019-12-03 12:01:40
I have a contenteditable div <div id="divTest" contenteditable="true"> I need to get the last word from caret position and on certain condition I have to test and remove this specific word only. Below is how am I doing $('#divTest').on('keyup focus', function (e) { if (e.keyCode == 32) { var lastWord = getWordPrecedingCaret(this), spanLastWord = $('#lastWord'); } }); function getWordPrecedingCaret(containerEl) { var preceding = "", sel, range, precedingRange; if (window.getSelection) { sel = window.getSelection(); if (sel.rangeCount > 0) { range = sel.getRangeAt(0).cloneRange(); range.collapse

How to divide a set of overlapping ranges into non-overlapping ranges?

*爱你&永不变心* 提交于 2019-12-03 11:55:57
Let's say you have a set of ranges: 0 - 100: 'a' 0 - 75: 'b' 95 - 150: 'c' 120 - 130: 'd' Obviously, these ranges overlap at certain points. How would you dissect these ranges to produce a list of non-overlapping ranges, while retaining information associated with their original range (in this case, the letter after the range)? For example, the results of the above after running the algorithm would be: 0 - 75: 'a', 'b' 76 - 94: 'a' 95 - 100: 'a', 'c' 101 - 119: 'c' 120 - 130: 'c', 'd' 131 - 150: 'c' I had the same question when writing a program to mix (partly overlapping) audio samples. What