How to set variable range with some cells in columns blank?

Jeddo

Board Regular
Joined
Jan 26, 2019
Messages
50
Office Version
  1. 2019
Platform
  1. Windows
I am trying to set a variable print range for retrieved data in which some of the cells may be blank. The range could be from one row up to 250 rows depending on the data retrieved. Columns A & B will not have any blank cells, but columns beyond C & D may have blank cells. As in the workbox below, I would need to set a print range of A1 to D17. I have a formula that will find the last row in column B, but I can't figure out how to set the range for two more columns to the right.

Range("A1", Range("B1").End(xlDown)).PrintOut

How do I set the print range to encompass columns C & D?

Print template.xlsx
ABCD
1Sold By: Me
2
3NameBusiness NamePhone #
41John 555-1234
52James
63Paul P&S Cattle Co.555-1236
74Henry555-1237
85George
96SusanAnytown Auto Parts555-1239
107Ginny555-1240
118EdithEdith's Closet555-1241
129Beatrice555-1242
1310Eric
1411Joe555-1244
1512ShawnShawn's Landscaping555-1245
1613Steven
1714Bobby
Sheet1
 
Since you are copying the code into an existing Sub, you need to get rid of these lines:
VBA Code:
Sub testFindAndPrint

and this line which is before the line, With Sheet1
VBA Code:
End Sub

(so not the one right at the end)
Got it to work!
This was for a program for a fund raiser for my church group and at the time, my mind was too cluttered with the upcoming event and I basically ran out of time to get it to work. Had some time, so sat down with a fresh mind and was able to make it work. Thanks so much for your help.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

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