Selecting several tables of varying size in non-contiguous range

Kentetsu

Well-known Member
Joined
Jan 22, 2004
Messages
520
I have a sheet with 6 tables of varying size (length & width). The furthest Column used will be Column J.

So, I need to start at the bottom of Column A and go up to find the first populated cell, then extend that range to the top of the sheet and over to Column J.

I don't know why I'm having so much difficulty with this, as I've done it before and it was pretty simple from what I recall. But I've been wracking my brain on this all day and getting no traction at all.

If anyone can give me a hand with this, I would really appreciate it.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Assuming that Column A contains text values, try defining the range as follows...

Code:
=$A$1:INDEX($J:$J,MATCH(REPT("z",255),$A:$A,1))

If Column A contains numerical values, replace...

Code:
REPT("z",255)

with

Code:
9.99999999999999E+307

Hope this helps!
 
Upvote 0
Thanks for taking the time to think on this Domenic. Unfortunately, Column A contains text, numbers, and dates.

I managed to declare a cell at the bottom corner of the range, intending to perform a selection between A1 and "EndOfData" but couldn't get the selection routine figured out. One of the few times Google has failed me. lol.

I finally broke down this afternoon and used the Macro Recorder, using ctrl up/down/sideways, etc. until the entire range was captured. I'm not happy with it because it isn't very elegant, but since the overall structure of the data shouldn't change I suppose it's a suitable solution.

Just in case you're curious at all, this is a project that involves opening several spreadsheets/copying data/formatting/adding formulas/deleting unneeded stuff/turning everything into tables/and then spitting the results out into an email. It is a one button shift Recap creator. It should save about 20 minutes per shift each day, which amounts to an hour per day, or 365 hours per year at an average rate of $17.00/hour which is $6,205 per year. I love this stuff. :) I do it in my spare time just for the fun of it.

I've got everything working now, just fine tuning and checking stability along with a few last tweaks.

Thanks again. And if you have any other ideas to tidy this up I'm always a very willing student.
 
Upvote 0
In that case, if Column A does not contain empty cells, try...

Code:
=OFFSET($A$1,0,0,COUNTA($A:$A),10)

Does this help?
 
Upvote 0
I need to start at the bottom of Column A and go up to find the first populated cell, then extend that range to the top of the sheet and over to Column J.
Like this?

Code:
[color=darkblue]Sub[/color] GetRange()
  [color=darkblue]Dim[/color] rng [color=darkblue]As[/color] Range
  
  [color=darkblue]Set[/color] rng = Range("A1", Range("A" & Rows.Count).End(xlUp)).Resize(, 10)
  MsgBox "Is this the range you want?" & vbLf & rng.Address(0, 0)
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Domenic,

Column A does contain blank cells. There is an empty row between each Table, otherwise they try to "join together" and get all messed up. So, Table/Blank row/Text (title)/Table/repeat.

Peter_SSs,

I can't test that at the moment but it looks suspiciously correct. :)

Thank you both for your assistance...
 
Upvote 0
Peter_SSs,

The result gives me the last row containing data, extending over to Column J. So, somehow it is not extending the range up to A1.

Here is the hodgepodge I am currently using, which does result in the correct range being selected. Ugly, ain't it? :)

Rich (BB code):
.Range("PasteFixedRacks")(2, 10).Select                                   (I just realized that this line will not work because the size of the table will be variable)
Selection.Name = "EndRange"                                                  (this is supposed to be the bottom right cell of the desired range)

Application.Goto Reference:="EndRange"
    .Range(Selection, Selection.End(xlUp)).Select
    .Range(Selection, Selection.End(xlUp)).Select
    .Range(Selection, Selection.End(xlUp)).Select
    .Range(Selection, Selection.End(xlToLeft)).Select
    .Range(Selection, Selection.End(xlToLeft)).Select
    Selection.Copy                                                                     (The next step is paste into email)

I was hoping that by setting that single cell as "EndRange" I would then be able to do something like this:

Rich (BB code):
.Range("A1:EndRange").copy

But having a hard time getting anywhere with that as well.

Thanks again...
 
Upvote 0
Peter's suggestion should return the desired result. So, for example, if A10 is the last cell in Column A that contains data, the reference returned should be "A1:J10", which I understand is what you want, correct? What's the reference that it returns?
 
Upvote 0
Let's say that A10 is the last cell in Column A of the active sheet that contains a value, are you saying that the reference returned would be A10:J10?
 
Upvote 0

Forum statistics

Threads
1,216,458
Messages
6,130,757
Members
449,588
Latest member
accountant606

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