I need to delete or clear multiple continuous rows say 29 to 47 but the row depends on the row index. Say row is 29 now, but the next run of the program the row is 47. I need to take the last row set entered and delete it. I know the start row and the end row values that I need to delete, but putting in code like Range("S13") to Range("S14") instead of Range(.(Rows(2),.Rows(20)).Delete Shift:xlup gives me syntax error or other errors depending On what I try.
Any suggestions would be greatly Appreciated
Related
I am trying to count the number of populated rows in Excel, but excluding the first row as this is used as a header. ie. I want to start counting from the second row.
The following works to count populated rows, including the first row:
=COUNTIF(Books!A:A, "<>")
Logically, this is what I want, but it doesn't work in Excel:
=COUNTIF(Books!A2:A, "<>")
Seems like this should be simple? Am I missing something obvious? Thanks in advance!
There are two possibilies:
Use the limit of Excel by entering the last possible row:
=COUNTIF(Books!A2:A1048576;"<>")
If the Header is always there, you could just substract it from the result:
=COUNTIF(Books!A:A, "<>")-1
You need to count until last row, so if your data finish in row 20, then:
=COUNTIF(Books!A2:A20, "<>")
But if your data change rows quantity very often sometimes 20, sometimes 40, sometimes 10, I suggest you use a Table (a Listobject) because it works as a dynamic range:
Create and format tables
My formula is:
=COUNTIF(Table1[Book Name],"<>")
Where Table1[Book Name] equals to range A2:A9 in this case. But if you add more data, Table1[Book Name] will refer to new range, and the formula will autoupdate :)
Using full qualified ranges as A:A may work and it's easy to use but it's a waste of resources checking a million cells every time you calculate. Besides, if you use a lot of formulas using full columns, it may overcharge the file and the time recalculations needs.
This array formula works beautifully for what I need:
=IF(S12="","","Fastest Loop Completed in "&TEXT(MIN(IF((S12:S1048576<>"")*(R12:R1048576<>""),S12:S1048576-R12:R1048576)),"[m]:ss"))
I've since added Column U that will either be blank or have a text string of "A" or "B". I want to update the above formula to perform the same function and continue to include rows where Column U is either blank or "A", but ignore rows where Column U contains "B". I've fiddled with AND(...,U<>"B"), but am not making any progress. This formula is just giving me "Fastest Loop Completed in 0:00":
=IF(S12="","","Fastest Loop Completed in "&TEXT(MIN(IF(AND((S12:S1048576<>"")*(R12:R1048576<>""),U12:U1048576<>"B"),S12:S1048576-R12:R1048576)),"[m]:ss"))
On a side note, is there a cleaner/lighter way to do (S12:S1048576<>"")*(R12:R1048576<>"") to accomplish the same result and have it only check where Column A isn't blank, without having it mindlessly looking at all rows? I.e., "where Column A isn't blank, Column U is not equal to "B" and there is a value in both R and S, then find the fastest time." The sheet could possibly be run with just a few rows or, I anticipate, up to tens of thousands of rows, so it needs to be flexible. I don't expect anyone to ever run 1 million rows (ha, I say that now...).
I was able to get the formula to work by converting the strings to numbers within an IF() statement:
=IF(S12="","","Fastest Loop Completed in "&TEXT(MIN(IF((S12:S1048576<>"")*(R12:R1048576<>"")*(IF(U12:U1048576="B","",1)<>""),S12:S1048576-R12:R1048576)),"[m]:ss"))
Still interested to know if there is a better way than using an IF() to accomplish this as well as a cleaner/lighter way to only check rows that have data.
I want to delete all the rows where dates in Column "X" are between year 01/01/2012 and 08/01/2014. I tried looking for a dummy code but couldn't find any.
Something like
for r = activesheet.cells(activesheet.rows.count,1).end(xlup).row to 1 step -1
if year(activesheet.rows(r).cells(1,"x").value)=2013 then
activesheet.rows(r).entirerow.delete
end if
next r
not test this, but this is how i'd do it, if it couldnt be done via filtering through VBA maybe?
It's no wonder that this takes forever. It has to calculate the whole if statement for 13000 cells.
Is this a one time only action? If yes, why dont you mark the whole table, then sort the data for column x. If column x is formatted as data then it should sort it normally (increasing or decreasing as you wish, I'd do it with increasing values) and then you can press ctrl+f, enter 08/01/2014 > press search and it should jump to the first line with this date. You can just delete everything above it. No need for codes that take for ever :)
As the title describes I am attempting to find a function that will return the last 12 values of column. The catch is that a new value will be added to the column on every month and I need the values to update automatically. My end result would ideally be a 12-row table that adjusts as I add new data to the source table. From the new table I want to make a Sparkline that would than also adjust. Does anyone know how to do this?
I attempted to use VLookup as well as Index and CountA but neither gave me what I was looking for. They only returned the last value but I need the last 12.
Thanks in advance for any help!
Denzel
If your list starts at A1:
=OFFSET(A1,COUNTA(A:A)-12,0,12,1)
entered into a 12-cell selection as an array formula (using Ctrl+Shift+Enter)
I want to read an Excel file in the way that only used rows has to be taken out i.e if the excel file contains 47 rows initially but only 10 rows are filled then that 10 rows data has to be read(Don't want to mention it like A2C7 while reading,need to do it by default) Is it possible to achieve in VB 6.0.Kindly help me to solve this.
Used Range Property has worked for me,but now i found another problem While using this method ,if i add a value in a row after the last used row and remove the value at once and saves the file , it is showing the wrong usedRange value (i.e) it is showing the address of the row where i added and removed the value at once.how to handle this?
Try reading in the loop till the row is non empty (used). You can get used rows count by the following syntax:
<workbookname>.Sheets("<SheetName>").UsedRange.Rows.Count
for example
Workbook1.Sheets("Sheet1").UsedRange.Rows.Count