VBA: select all the cell from a specific one to the last with values - vba

My aim is to select with VBA for example all the cells from A1 to A10 (the last one with values).
Is the function AllValueDowns applicable? If so, how does it work?

Related

Conditional Formatting (If/when)

Ok so I want a row to highlight red when the date in cell C1 is more than the cell in B1, but only if this is a difference of two months or less. I am sorry, I don't know how to embed a dummy spreadsheet. So for example, if B1 (clinic appointment due date) is Sep-17 and C1 (physical checks due date) is Oct-17, I want this row to highlight. If C1 is Dec-17, I don't want the row to highlight because this is more than two months from Sep-17.
Edited based on your new description, using Column A to represent Clinic Appointment Date and Column B to represent Physical Checks Due Date.
Use a rule based on DAYS().
Click on cell A1
Choose New rule from the Conditional Formatting menu.
Choose Use a formula to determine which cells to format
In Format values where this formula is true:, use the below formula:
=DAYS(B1, A1) < 60
Set up the formatting you want to use to highlight the cells. In the image below, I've set the ones that meet your requirements for highlighting to appear in red, and applied it to the first two rows in Column A (A1 and A2):
Here's the sheet with sample data in two rows, showing the conditional formatting working as requested:

How to replace an empty cell in formula with last numbered cell

Working on a budget worksheet. I am trying to get the cell to keep looking up the column for one part of the formula if the previous cell is blank.
I currently have the formula to give a blank cell in the 'Remaining' column (E) if the 'Budgeted' column (C) is blank, as seen here
Budget clip
The issue comes when trying to get a number in the 'Remaining' column when the previous cell above is blank. I would like it to keep looking up the column until it finds a number, then use that number in the equation.
So in the picture, for Expense 5 (A9) I would like it to take cell E6-C9.
And then repeat the formula down the column.
I would like to copy the formula down the column since filled and unfilled cells will change from month to month.
Try this in cell E9
=IF(C9>0,$C$3-SUM(C$5:C9),"")
I think this will serve the same purpose as calculating E6 - C9 (i.e. calculating how much of the budget is remaining), but it's simpler code.
You should be able to copy it from E5 to the bottom of your table using regular copy-and-paste.

subtract the last two non-empty cell in excel

This is I think a simple problem but I can't seem to find the right solution for it. I don't know if VBA is needed for it. Basically I just want to subtract the last two non-empty cell in Excel. Example: I have the cell A1 and cell B1 and then subtract the value of A1 from B1 and place this value at the same row but another column C1 and so on. I have read this to get the last non-empty cell but I need two non-empty cell and perform operation on them.
=LOOKUP(2,1/(A:A<>""),A:A)
Is there an easier way to do this? Or should I use VBA?
EDIT:
the reason is I'm making a somewhat similar to a balance sheet but a simple one, the user will just enter deposited value at the first column and expenses at the second column and then display the balance in the third column.. and vice versa.
EDIT:
Sample
Put this in C4 and copy down:
=SUM($A$3:$A4)-SUM($B$3:$B4)
If you want to copy the formula past the data so it will automatically fill when data is inserted you can do what #Dirk stated:
=IF(A4&B4<>"",SUM(A$3:A4)-SUM(B$3:B4),"")
Put it in C4 and copy down as far as desired.
This way you can fill the column with the formula and as the data is filled it will change from the empty string to the running total.
EDIT:
Regular formula:
=IF(ROW($C1)=1,OFFSET($C1,0,-2)-OFFSET($C1,0,-1),OFFSET($C1,-1,0)+OFFSET($C1,0,-2)-OFFSET($C1,0,-1))
in cell C3 put "=A3-B3" in cell C4 put "=C3+A4-B4" then copy down.
This will start the balance at 3000 in C3 then add any deposits or minus any withdrawals to the rest of column C.

How to autofill a cell down based on a variable value 'n'

I am calculating a variable number of rows in cell C1, which I need to autofill down by, in cell B1. For example, if C1 returns the number '3', then I need to autofill cell B1 down three rows.
Any way to do this using a logic function or VBA?
Put this in B2 and copy down:
=IF(ROW()<=$C$1,$B$1,"")
Range("B1").Resize(Range("C1").Value,1).FillDown

sorting range based on other column values in Excel 2010

I have excel sheet contain data as below:
what we need is sorting range D2:E10 based on Column A values
we need result to be like this:
Is there any method allow us to do that?
(we recommend not to use macro if possible)
the closest solution with no macros is
select column a and d
use conditional fomat -> highlight cells Rules --> duplicated values
now all douplicted values cell color chaned
select range A2:B7 and custom sort using cell color, not colored cells at bottom
do the same with range D2:E10
hope this help you
I find some workaround solution
in cell F2 I used
=VLOOKUP(A2;$D$2:$E$20;1;FALSE)
and in cell G2
=VLOOKUP(A2;$D$2:$E$20;2;FALSE)
copy formulas to range F3: G10
this gives me some result but some data in range D2:E10 lost such as D4, D5 ...etc (not copied in column F and G )