ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   proper syntax in code needed (https://www.excelbanter.com/excel-programming/310429-proper-syntax-code-needed.html)

Jim May

proper syntax in code needed
 
I need to use something like this in my code:
Activesheet.PageSetup.PrintArea = "$A$1:$C$5"

but I need to substitute the address range above to or as follows:

Where I already have a variable "Lrow" = 7122

I wish to print the area:

A7082 (<< this # set to Lrow minus 40) : H7122

I can't get syntax to work - I've tried:

PrtRng = Range("A & LRow - 45 & ":I" & LRow) << Not being accepted

Tks in Advance for helping,,



Gary Brown[_7_]

proper syntax in code needed
 
Looks like you may be missing a quotation mark. Try...
PrtRng = Range("A" & LRow - 45 & ":I" & LRow)
'not tested.
HTH,
Gary Brown


"Jim May" wrote in message news:mr03d.12$GU2.1@lakeread06...
I need to use something like this in my code:
Activesheet.PageSetup.PrintArea = "$A$1:$C$5"

but I need to substitute the address range above to or as follows:

Where I already have a variable "Lrow" = 7122

I wish to print the area:

A7082 (<< this # set to Lrow minus 40) : H7122

I can't get syntax to work - I've tried:

PrtRng = Range("A & LRow - 45 & ":I" & LRow) << Not being accepted

Tks in Advance for helping,,





Tom Ogilvy

proper syntax in code needed
 
PrintArea is looking for a string.

You are missing a double quote in your concatenation. should be:

? "A" & LRow - 45 & ":I" & LRow
A7077:I7122


then
Dim prtRng as String

prtRng = Range( "A" & LRow - 45 & ":I" & LRow).Address(external:=True)

Activesheet.PageSetup.PrintArea = prtRng

Change 45 to 40 if you actually want 7082

--
Regards,
Tom Ogilvy


"Jim May" wrote in message news:mr03d.12$GU2.1@lakeread06...
I need to use something like this in my code:
Activesheet.PageSetup.PrintArea = "$A$1:$C$5"

but I need to substitute the address range above to or as follows:

Where I already have a variable "Lrow" = 7122

I wish to print the area:

A7082 (<< this # set to Lrow minus 40) : H7122

I can't get syntax to work - I've tried:

PrtRng = Range("A & LRow - 45 & ":I" & LRow) << Not being accepted

Tks in Advance for helping,,






All times are GMT +1. The time now is 03:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com