Excel VBA - Copy Table but leave out Blank Spaces

travisdh

New Member
Joined
Jun 21, 2010
Messages
5
Hi All,

I have a dynamic table in a spreadsheet (but not a pivot-table) which basically looks in another sheet to see if a value is in that sheet and if so it populates the value in a second sheet. The idea is basically that we collect measurements in a specific (but variable) number of locations to show them on the sheet. The sheet then shows at the end the average and some other measurements.

One example is like the below:

LevelLocationTimeMeasurement AMeasurement BMeasurement C
1​
NAM
20​
25​
24​
1​
SAM
21​
25​
19​
1​
EAM
23​
20​
20​
1​
WAM
23​
25​
21​
2​
NAM
21​
21​
20​
2​
SAM
23​
24​
25​
2​
EAM
19​
21​
22​
2​
WAM
24​
24​
24​
3​
NAM
24​
19​
22​
3​
SAM
24​
24​
23​
3​
EAM
19​
24​
22​
3​
WAM
25​
22​
25​
Outside
20​
22​
24​
xx
Average
22​
23​
22​
xx

If there was a smaller number of measurements there would be more of a gap between say Level 3 (W) and the Outside value, this could be 10 cells, it could be 2, or it could be more depending on how many levels have been tested.

What I am trying to do is to copy the table, but essentially remove the white space between the last measurement (in Level & Location), and the Outside / Average measurements which are on the table below. My issue is that this table is dynamic though, so I can't grab the whole table as there will be heaps of whitespace that I don't want to copy into a word report.

I know that the columns will be consistent, but not the rows. Does anyone have a code sample that might deal with something like this, where the data set stops, and there is an end set of rows, and they effectively want to copy the data like it is more like the below:

LevelLocationTimeMeasurement AMeasurement BMeasurement C
1​
NAM
20​
25​
24​
1​
SAM
21​
25​
19​
1​
EAM
23​
20​
20​
1​
WAM
23​
25​
21​
2​
NAM
21​
21​
20​
2​
SAM
23​
24​
25​
2​
EAM
19​
21​
22​
2​
WAM
24​
24​
24​
3​
NAM
24​
19​
22​
3​
SAM
24​
24​
23​
3​
EAM
19​
24​
22​
3​
WAM
25​
22​
25​
Outside
20​
22​
24​
xx
Average
22​
23​
22​
xx

I am fine with copying data from between excel and word using VBA, just not too clear on how to best select the table leaving out whitespace, if it helps i know the maximum the table could ever be, and in the spreadsheet I do have the ability to work out how many locations and levels were tested so I could work out how many rows (i.e., 3 * 4) but is there a better way to do it to be able to copy a table and leave out the blank rows?

Many thanks!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Sorry the table went silly, its often something like the below

LevelLocationTimeMeasurement AMeasurement BMeasurement C
1​
NAM
20​
25​
24​
1​
SAM
21​
25​
19​
1​
EAM
23​
20​
20​
1​
WAM
23​
25​
21​
2​
NAM
21​
21​
20​
2​
SAM
23​
24​
25​
2​
EAM
19​
21​
22​
2​
WAM
24​
24​
24​
3​
NAM
24​
19​
22​
3​
SAM
24​
24​
23​
3​
EAM
19​
24​
22​
3​
WAM
25​
22​
25​
Outside
20​
22​
24​
Average
22​
23​
22​
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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