Variable Row labels

corquando

Board Regular
Joined
Jan 8, 2009
Messages
82
Hello, all.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I apologize if this is a re-tread. I looked for a good hour and did not see the topic addressed, but this doesn't mean I didn't miss a generic title or stop a page short; mea culpa if we've seen this before.<o:p></o:p>
<o:p></o:p>
I have a simple task, whereby a daily report is run. A number of rows are transferred to another sheet within the workbook; the column counts can vary, as well as the number of rows, and desired previous data will be on the target worksheet. New data are always pasted below old.<o:p></o:p>
<o:p></o:p>
Having pasted the new data, I count the new number of populated rows:<o:p></o:p>
<o:p> </o:p>
Range("A1").Select
Range(Selection, Selection.End(xlDown)) Select
MyRows = ActiveWindow.RangeSelection.Rows.Count<o:p></o:p>

<o:p> </o:p>
<o:p></o:p>
Using "MyRows," I want to be able to clean up any rows' garbage below the populated rows. If it were always the same number, I could say:<o:p></o:p>
<o:p></o:p>
Rows("10:200").Delete, or<o:p></o:p>
Rows("27:300").ClearContents <o:p></o:p>
<o:p></o:p>
or some such. <o:p></o:p>
<o:p></o:p>
But I don't know how to substitute "MyRows + 1" and "MyRows + 200" (e.g.) for the row labels - I'm sure it's exceedingly simple and I'm almost embarrassed to ask, but I can't find this anywhere. I’m hoping to avoid time-consuming loops, as the potential for this to grow to thousands of rows is quite real, and a simple, one- or two-line command would be so much more efficient.<o:p></o:p>
<o:p> </o:p>
Thanks.<o:p></o:p>
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
you can shorten the first bit to

Code:
myrows = Range("A1").End(xlDown).Row

for the second bit try

Code:
Cells(myrows + 1, 1).Resize(300, Columns.Count).ClearContents
 
Upvote 0
I knew it would be simple, but I didn't expect the bonus. The first bit is excellent.

Thanks - I'm happily rewriting!
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,448
Members
448,966
Latest member
DannyC96

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