VBA coding - SET RNG

btsboarder

New Member
Joined
Jun 28, 2013
Messages
9
Hi All,

I am trying to have my VBA code grab all the information in the relevant range, but not pick up any empty lines, i.e stop when there is no more information. This is the code I have right now.

Set rng = Nothing
Set rng = Range("B5:H31").SpecialCells(xlCellTypeVisible)

So say my information only goes to row 20, I don't want it to continue until row 31. I have it set up to paste the information into an email, so I want to cut down on white noise.

Thanks!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Maybe:
set rng = range("B5:H" & range("B5").end(xldown).row)

Cell type visible works with hidden rows, not just empty rows. Using xldown will be the equivalent of selecting B5 and then hitting Ctrl + down arrow.
 
Upvote 0
So I have a range that has formulas in rows B:H to row 30. So the control down will select the formulas. They pull if information is entered in column A. So if now information is given in column A, it'll be blank. But that code still thinks control down to the end. Thoughts?
 
Upvote 0
pplstuff was on the right track, but now that we know column B is filled with formulas referring to column A, then we can use column A to find the last row

Try
set rng = range("B5:H" & range("A5").end(xldown).row)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,728
Messages
6,132,360
Members
449,720
Latest member
NJOO7

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