Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

VBA Fill down

0

I have a 3 tab worksheet.  Data is entered  or downloaded into tab 1, always a different length.  Tab 2 transfers info from tab 1 and may add computations in this case a8:k8.Tab 3 draws info from 1 and 2 and may also add computations into a7:m7.  Tab 2 must display "END" as text in the last cell of column C.  Using the ranges above, I would like a vba that fills down to the last row.  Example. Sheet 1 shows 15 employees.  Sheet 2 needs to fill data down through the last employee and then add "End" into the last row in C.  Sheet 3 will do likewise with its range.  I've already invested hours into examples that end up carrying down a single column.  I've chosen a range in advance such as a8:k100 but that leaves my data unclean and filled with zeros.  It would be most helpful if you could comment out lines ahead of the code describing the purpose of the code.

Dave

Answer
Discuss

Discussion

Please attach your workbook to your question.
Variatus (rep: 4889) May 2, '18 at 8:50 pm
Done, sorry.
Dave
davish May 3, '18 at 12:29 pm
An important note: The formula in cell C7  of the PBU tab refers to a static cell which is F1.  In other words C7=B7*F1, C8=B8*F1, C9=B9*F1 and so on.
Dave
davish May 3, '18 at 3:59 pm
Add to Discussion

Answers

0

If you want to use VBA you shouldn't limit your ability to do so by insisting on using worksheet formulas as well. Its like wrestling with one arm tied behind your back and, considering your lack of experience, the other one broken lol:. Therefore I suggest a purely worksheet based solution at first. In this thread I shall show you how to avoid zeroes caused by copied blank cells.

In the attached workbook I have modified the formulas on the XTC tab. The idea is that you can copy the formulas down for many more rows than you will ever need. All of them will stay blank if the referenced cells in the WEEKLY tab are blank except for the last row in column A which will show "END" against the first row which is blank on the WEEKLY tab.

I draw your attention to the formula in XTC!J8 and its simplified form in J9.

[J8] =IF(SUM($F8),MAX(SUM($F8)-40,0),"")
[J9]  =IF($F9,MAX($F9-40,0),0)

J8 refers to [F8] =IF(WEEKLY!$Q13,MIN(WEEKLY!$Q13,40),"") which has a value of "" (because WEEKLY!$Q13 is blank) which looks blank but is a text strong of 0 byte length, meaning it is not zero. In fact, it isn't a number at all. Technically speaking it's a word. Therefore, when J8 asks if it is a number >0 the answer is an error. To overcome this problem J8 asks if SUM(F8) > 0. Excel's SUM() function interprets "" as 0.

F9 has no formula in it. It has a format of General and asked if it is zero it responds in the affirmative. Therefore the formula in J9 doesn't require SUM(F9). The plain reference to F9 will do. Copy F8 to F9 and J9 will show an error. Then change the formula in F9 to =IF(WEEKLY!$Q14,MIN(WEEKLY!$Q14,40),0) - replacing the "" with 0 - and J9 works again but F9 shows a zero which you don't want.

How to get rid of this zero is demonstrated in J9 (which also returns a zero which, however, is invisible. This has been achieved by setting a number format which displays a blank when the cell's value is zero. In the case of J9 that format is 0.00;0.00; For F9 the format should be 0;-0; Try it out on F9. The trick is that a cell format has 4 settings, separated by semi-colons: positive number, negative number, zero and text. So, you set the format as 0 for positive (meaning integers, no decimals), -0 for negative and Nothing for zero, indicated by the semi-colon with nothing following it. BTW, a custom format of ;;; would display nothing, whatever you enter in the cell such formatted.

Look at the formulas on your PBU tab. They are all upset by the null strings I introduced on the XTC tab. I recommend you change all those formulas to return 0 instead of "" and format the cells to hide the zeros. Then transfer the method introduced on the XTC tab to the way the PBU tab works and your problem should be solved. Without VBA.

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login