Need to copy a formula down to the next blank line that varies.

HTannenbaum

New Member
Joined
Feb 5, 2018
Messages
6
I have a spreadsheet containing different groups of data, each of which vary in number of lines, separated by single blank lines. The number of groups also varies from month to month. I can find the last line of a particular group using 'SelectionEnd(xlDown).Select' with no problem but i don't know how to capture the row number of that last row. I need that to AutoFill a formula in the adjoining column. I plan on looping through this logic depending on the number of "groups' of lines I find. Any help will be appreciated.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi

It's hard to answer definitively without seeing the data and the code but this statement:
Code:
MsgBox Selection.Row
Will show the row number of your current selection. This value can then be used to construct your formula.
e.g. .Range("L" & Selection.Row).Formula = "=K" & Selection.Row.

If the selection row is 6 then this will put the formula =K6 into cell L6. Modify to suit.

I trust this helps.
Andrew
 
Upvote 0
I can find the last line of a particular group using 'SelectionEnd(xlDown).Select' with no problem but i don't know how to capture the row number of that last row.

If as you state you can find the last line of each group each time with
Code:
Selection.End(xlDown)
then isn't the row number of that last line just
Code:
MsgBox Selection.End(xlDown).Row

:confused:

You will probably find if you explain in more detail what you are doing (as Andrew implied) there is a more efficient way of achieving what you want rather than use Select/Selection.
 
Last edited:
Upvote 0
I'm not sure how to post my worksheet here, but this is what I have. Again, any help is appreciated!

[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64, align: right"]425.58[/TD]
[TD="width: 64, align: right"]123[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]234[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]345[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]456[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]456[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]234[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]2325[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]235[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]235[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]356[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]256[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]32456[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]3456[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]32456[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
What column is the data with the spaces in?
Are the numbers constants or the result of formulas?
Are the blank cells truly blank or are they empty strings from the result of formulas using ""?
What column is the column with the formulas?
What is the first cell with the formula?
What is the formula in the first cell?
 
Last edited:
Upvote 0
I'm not sure how to post my worksheet here, but this is what I have. Again, any help is appreciated!

[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64, align: right"]425.58[/TD]
[TD="width: 64, align: right"]123[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]234[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]345[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]456[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]456[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]234[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]2325[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]235[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]235[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]356[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]256[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]32456[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]3456[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]32456[/TD]
[/TR]
</tbody>[/TABLE]
What row number does the above data start on?

What columns is the data in?

What formula are you trying to put in the next column?
 
Upvote 0
Cell A1 contains the formula.
Column B contains several sets of data that vary in number of rows each month.
I am trying to propagate the formula in A1 through the last row in column B.

Some background:

The formula is actually in the first row of column B and varies with each group of entries in column B. There is a blank line after the last entry in each group in column B.

I can move the formula to the correct corresponding row in column A for the first group. It is here that I have the problem. I don't know how to AutoFill to a variable number of rows.

After that formula is populated in column A for each entry in column B, I am assuming I will know the address of the last row and can easily determine the starting row of the next group in column B and can go through this process again.

When I record a macro to do this, the macro uses absolute addresses for the AutoFill function. That's where I get lost. I don't know how to modify that for the variable number of rows needed.

(I downloaded "MrExcel HTML Maker" and there were no instructions! I tried everything I knew as to how to use it and couldn't. That's a problem for another day. I did try to figure it out to give you a better look at the spreadsheet but have the original problem to solve first.)
 
Upvote 0
If the 425.58 is in cell A2, the following might work.
Code:
Range(Cells(2, 1), Cells(Cells(Rows.Count, 2).End(xlUp).Row, 1)).FillDown
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top