Macro sum only filtered cells in table and copy to clipboard - vba

I'm trying to do some data entry and was wondering if I could copy the sum of FILTERED data onto clipboard with a macro?
I have a macro that copies sum of selected cells, but when in a table format and filtering it seems to sum everything in that range too. Please let me know.
There are 1665 Rows total in my data table starting at 22.
Thanks!

No need to really use a macro, you can use the SUMIFS function https://support.office.com/en-in/article/SUMIFS-function-9dd6179e-cced-41dd-ac38-08fdf5b929e5 Basically you will use the criteria for filtering as the criteria for summing the values. I am not sure what your filtering criteria is, but let's you are filtering value that are great than 0 in column A rows 1 to 100.
SUMIFS(A1:A100, A1:A100, ">0")

Right click on the table and click Table->Totals Row to show a row at the bottom of the table for totals. It will only sum the visible rows of that column.

Related

Copy data from another sheet with 4 rows between each entry

I am working with three excel sheets within the same workbook, Data, Calculations, and Results. As you will see, the entries in column A are the focus.
Using the formula Data!A# (row number), those entries from the A column of Data are copied onto column A of the Calculate page. Between each entry from Data, there are three rows of calculations. On the last page (Results), I am looking for a formula/VBA code that will allow me to grab column A from Calculate without the three rows in between them.
Currently, I am experimenting with an offset function: OFFSET(Calculate!$A$2,(ROW()-1)*2,0). When I copy the forumla down, zeroes appear in some rows in place of the actual values. (Note A1 of Results is =Calculate!A2.)
How can I copy the entries from the Calculate sheet without a function returning zeroes as placeholders?
Data Sheet
Calculations Sheet
Results Sheet
You can accomplish this using the indirect function:
=INDIRECT("Calculate!$A$"&(ROW()-1)*4+1)
With that formula in A1:A4 of the results sheet, you should get the values you want from A1, A5, A9, A13 on the Calculate sheet.

Find number of rows in an already filtered Column A in Excel

I have got an Excel spreadsheet. This spreadsheet has just one tab in it. The Tab name is dynamic in nature and changes every week also the number of rows.
I have column A filtered already with a VBA macro. A1 has the header.
Now, I wanna find how many rows are there in this already filtered column A.
I am looking for any VBA function.
I have tried using Subtotal function.
=Subtotal(103,A2:A1345)
But I don't know the end range. As of now the end range is A1345. It will change every time in future if the new rows are added.
I tried multiple things but those did not work. I am quite new to VBA.
If A1 will never be blank, you could use (in a column other than A)
=Subtotal(103,A:A)-1.
Or, if there will be data below your table not to be counted, then format your table as a Table and use structured references (and this formula could go into column A)
=SUBTOTAL(103,Table1[column_header])
You can put the formula in column A if you use another column's last populated cell as the demarcation point.
If column B contains numbers then,
=subtotal(103, a2:index(a:a, match(1e99, b:b)))
If column B contains text then,
=subtotal(103, a2:index(a:a, match("zzz", b:b)))

How to record a macro in Excel that works on any number of rows?

I have recorded a macro in Excel that sums B2 and C2 into D2. I clicked on the lower right corner of D2 to extend the computation onto all rows.
Now, when I use this macro on other tables, it computes always the same number of rows as in the original table.
How can I record the macro so that it recognizes the height of the table and acts accordingly?
Is this possible without VBA programming?
You might be able to do that using the OFFSET() formula and avoiding a macro.
OFFSET(reference, rows, cols, [height], [width])
These two give the same result.
=SUM(B2:C2)
=SUM(OFFSET(B2,0,0,1,2))
You could count the rows in the table and use that to feed the height of your OFFSET formula.
=SUM(OFFSET(B2,0,0,1,COUNT(B:B))

VBA: Is there a way to apply a single formula to a column without looping through each cell

I'm quite new in VBA and was looking for ways on how to apply the same formula to all cells in a column. I have 5000 rows and I would simply like to multiply row values in Column 1 with row values in Column 2 and show the results of the same row in Column 3.
I have tried looping through each of the cells:
For i = 1 to 5000
Next i
but the calculation was slow and was wondering if there is another way to calculate all 5000 rows quicker.
I actually have 60 columns with different formulas and conditional statements which slows down the calculation process. I am actually looking for a simpler way to 'BULK' apply a certain formula to the whole column.
The following code makes Column1*Column2=Column3 using Formula property of Range object without a looping
Sheet1.Range("C1:C5000").Formula = "=RC[-2]*RC[-1]"

VBA Drag down Vlookup

All,
I have a data sheet of around 1.000 values which need a matching amount (the amount of valueschanges every day) . These amounts can be found in another tab "Data".
so using a Vlookup code in VBA should help me. The code I'm using is:
Sheets("Data").Range("E2") = Application.WorksheetFunction.VLookup(Sheets("Data").Range("D2"), Sheets("Blocked").Range("C:D"), 2, False)
Result should appear in column E responding with the row of the lookup_value which can be found in column D.The table and column index don't change being Sheets("Blocked").Range("C:D")and 2
This code gives me the result I wanted but as I tried to drag down the formula with this function:
Range("E2").AutoFill Destination:=Range("E2:E440")
How can I drag down this formula without needing to create a seperate vlookup for each row?
You should use the Formula as an R1C1 reference and then u will be able to drag down
Sheets("Data").Range("E2").FormulaR1C1 = "=VLookup('Data'!R[-1]C,'Blocked'!C[-2]:C[-1],2,0)"