Selecting a Data Range

Muleskin57

New Member
Joined
Dec 22, 2016
Messages
23
Hello,
I'm creating a tool for teachers using a "table" that is formatted as a data range. The last column has a formula that produces a time stamp for entries. I'd like to create a macro that copies all the lines, from cell A2 to the last timestamp in column O to another sheet. So I need to be able to find and select that range. Any ideas?

Thanks.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Change sheet names and destination range to suit
Code:
Sheets("Sheet1").Range("A2:O" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row).Copy Sheets("Sheet2").Range("A2")

Assumes that Column A is your longest column
 
Upvote 0
Thanks for the quick response, but that seems to select the entire table, doesn't end with the last timestamp produced in column O.
 
Upvote 0
If Column O is the longest column change
Code:
Range("A" & Rows.Count)
to
Code:
Range("O" & Rows.Count)

as long as the cells below are truly blanks and not formulas returning "".
 
Last edited:
Upvote 0
Yes, the cells have a formula returning a "". I need to select A2 to the last non-"" cell in column O.
 
Upvote 0
Code:
Dim LstRw As Long
LstRw = Sheets("Sheet1").Columns("O").Find("*", , xlValues, , xlByRows, xlPrevious).Row
Sheets("Sheet1").Range("A2:O" & LstRw).Copy Sheets("Sheet2").Range("A2")
 
Upvote 0

Forum statistics

Threads
1,215,544
Messages
6,125,434
Members
449,223
Latest member
Narrian

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