ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   syntax error (https://www.excelbanter.com/excel-programming/348575-syntax-error.html)

JT

syntax error
 
I'm trying to select several ranges at the same time with variable and am
getting an error message. I'm sure it is a syntax issue. Following is the
code in question. I'd appreciate any help with resolving this issue. Thanks
for the help.

Range(("A" & frow, "A" & lrow), ("C" & frow, "C" & lrow), ("E" & frow, "F" &
lrow), ("H" & frow, "I" & lrow)).select

frow is a variable I set for the first row of data and lrow is a variable I
set for the last row of data.

Thanks again for all of the help......
--
JT

Dave Peterson

syntax error
 
One way:

Dim fRow As Long
Dim lRow As Long

fRow = 5
lRow = 10

Range("A" & fRow & ":A" & lRow _
& ",C" & fRow & ":C" & lRow _
& ",E" & fRow & ":F" & lRow _
& ",H" & fRow & ":I" & lRow).Select

or something like (I like it better):

Union(Range(Cells(fRow, "A"), Cells(lRow, "A")), _
Range(Cells(fRow, "C"), Cells(lRow, "C")), _
Range(Cells(fRow, "E"), Cells(lRow, "F")), _
Range(Cells(fRow, "H"), Cells(lRow, "I"))).Select




JT wrote:

I'm trying to select several ranges at the same time with variable and am
getting an error message. I'm sure it is a syntax issue. Following is the
code in question. I'd appreciate any help with resolving this issue. Thanks
for the help.

Range(("A" & frow, "A" & lrow), ("C" & frow, "C" & lrow), ("E" & frow, "F" &
lrow), ("H" & frow, "I" & lrow)).select

frow is a variable I set for the first row of data and lrow is a variable I
set for the last row of data.

Thanks again for all of the help......
--
JT


--

Dave Peterson

Kris

syntax error
 
JT wrote:
I'm trying to select several ranges at the same time with variable and am
getting an error message. I'm sure it is a syntax issue. Following is the
code in question. I'd appreciate any help with resolving this issue. Thanks
for the help.

Range(("A" & frow, "A" & lrow), ("C" & frow, "C" & lrow), ("E" & frow, "F" &
lrow), ("H" & frow, "I" & lrow)).select

frow is a variable I set for the first row of data and lrow is a variable I
set for the last row of data.

Thanks again for all of the help......



":" not ,

"A" & frow & ":A" & lrow


All times are GMT +1. The time now is 08:54 PM.

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