Printing an area decided by criteria

Ibbo1978

New Member
Joined
Mar 6, 2017
Messages
20
Hi Guys,

I hope you can help as always.

I have a file that I want to print up to a certain row which contains the word "END". If there is no "END" in that column, I want a message state that.

I have set up a Formula to automate the name range and added a button to simply print the print area, although feel I can do all the above within VBA with a little assistance.

Please advise,

Ibbo
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this

Replace following values with correct values for your worksheet
- Top Left cell of print area $B$2
- Column where "END" is to be found A
- Last column to print F


Code:
Sub Set_Print_Area()
    
With ActiveSheet
    On Error GoTo Oops
    .PageSetup.PrintArea = "[COLOR=#ff0000]$B$2[/COLOR]" & ":" & Cells(.Columns("[COLOR=#0000cd]A[/COLOR]").Find("END", lookat:=xlWhole).Row, "[COLOR=#800080]F[/COLOR]").Address
End With

Exit Sub
Oops: MsgBox "Where has the END gone?", vbCritical, "oops!"
End Sub
 
Last edited:
Upvote 0
Code:
Sub Set_Print_Area()
    
With ActiveSheet
    On Error GoTo Oops
    .PageSetup.PrintArea = "$B$2" & ":" & Cells(.Columns("A").Find("END", lookat:=xlWhole).Row, "F").Address
 [COLOR=#ff0000]   .PrintOut[/COLOR]
End With

Exit Sub
Oops: MsgBox "Where has the END gone?", vbCritical, "oops!"
End Sub
 
Upvote 0
1. Post ENTIRE code that you are using
2. Which columns are you trying to print ?
3. Which column contains "END" ?
4. Which row should be the first row to print ?
 
Upvote 0
Sub Print_ETG()
With ActiveSheet
On Error GoTo Oops
.PageSetup.PrintArea = "$A$1" & ":" & Cells(.Columns("C").Find("END", lookat:=xlWhole).Row, "C").Address
.PrintOut
End With

Exit Sub
Oops: MsgBox "Where has the END gone?", vbCritical, "oops!"
End Sub


I need to:
Print A:N
Column containing "END" is C
Print Row 1 until row containing "END" or more ideally row previous to row containing "END"

Thanks again
 
Upvote 0
or ideally row previous to row containing "END"
- adjusted like this:
Code:
    .PageSetup.PrintArea = "$A$1" & ":" & Cells(.Columns("C").Find("End", lookat:=xlWhole).[COLOR=#006400]Row - 1[/COLOR], "N").Address


With code as amended below, and worksheet as copied below ...the print range that is printed for me is A1:N26


Code:
Sub Set_Print_Area()
    
With ActiveSheet
    On Error GoTo Oops
    .PageSetup.PrintArea = "[COLOR=#ff0000]$A$1[/COLOR]" & ":" & Cells(.Columns("[COLOR=#ff0000]C[/COLOR]").Find("END", lookat:=xlWhole).[COLOR=#006400]Row - 1[/COLOR], "[COLOR=#ff0000]N[/COLOR]").Address
    .PrintOut
End With
    
Exit Sub
Oops: MsgBox "Where has the END gone?", vbCritical, "oops!"
End Sub

Excel 2016 (Windows) 32 bit
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
1
a1b1c1d1e1f1g1h1i1j1k1l1m1n1
2
a2b2c2d2e2f2g2h2i2j2k2l2m2n2
3
a3b3c3d3e3f3g3h3i3j3k3l3m3n3
4
a4b4c4d4e4f4g4h4i4j4k4l4m4n4
5
a5b5c5d5e5f5g5h5i5j5k5l5m5n5
6
a6b6d6e6f6g6h6i6j6k6l6m6n6
7
a7b7c7d7e7f7g7h7i7j7k7l7m7n7
8
a8b8c8d8e8f8g8h8i8j8k8l8m8n8
9
a9b9c9d9e9f9g9h9i9j9k9l9m9n9
10
a10b10c10d10e10f10g10h10i10j10k10l10m10n10
11
a11b11c11d11e11f11g11h11i11j11k11l11m11n11
12
a12b12c12d12e12f12g12h12i12j12k12l12m12n12
13
a13b13c13d13e13f13g13h13i13j13k13l13m13n13
14
a14b14c14d14e14f14g14h14i14j14k14l14m14n14
15
a15b15c15d15e15f15g15h15i15j15k15l15m15n15
16
a16b16c16d16e16f16g16h16i16j16k16l16m16n16
17
a17b17c17d17e17f17g17h17i17j17k17l17m17n17
18
a18b18d18e18f18g18h18i18j18k18l18m18n18
19
a19b19c19d19e19f19g19h19i19j19k19l19m19n19
20
a20b20c20d20e20f20g20h20i20j20k20l20m20n20
21
a21b21c21d21e21f21g21h21i21j21k21l21m21n21
22
a22b22c22d22e22f22g22h22i22j22k22l22m22n22
23
a23b23c23d23e23f23g23h23i23j23k23l23m23n23
24
a24b24c24d24e24f24g24h24i24j24k24l24m24n24
25
a25b25c25d25e25f25g25h25i25j25k25l25m25n25
26
a26b26c26d26e26f26g26h26i26j26k26l26m26n26
27
a27b27endd27e27f27g27h27i27j27k27l27m27n27
28
a28b28c28d28e28f28g28h28i28j28k28l28m28n28
29
a29b29c29d29e29f29g29h29i29j29k29l29m29n29
30
a30b30c30d30e30f30g30h30i30j30k30l30m30n30
31
a31b31c31d31e31f31g31h31i31j31k31l31m31n31
32
a32b32c32d32e32f32g32h32i32j32k32l32m32n32
33
a33b33c33d33e33f33g33h33i33j33k33l33m33n33
34
a34b34c34d34e34f34g34h34i34j34k34l34m34n34
35
a35b35c35d35e35f35g35h35i35j35k35l35m35n35
Sheet: Sheet2
 
Upvote 0
it was my mistake due to "END" being the result of a formula, I have now fixed it.

Thanks foal your assistance
 
Upvote 0
it was my mistake due to "END" being the result of a formula

add an extra attribute (as below) and it will also work if cell contains a formula which returns "end" ...

Code:
.PageSetup.PrintArea = "$A$1" & ":" & Cells(.Columns("C").Find("END", lookat:=xlWhole[COLOR=#ff0000], LookIn:=xlValues)[/COLOR].Row - 1, "N").Address
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,228
Members
448,951
Latest member
jennlynn

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