ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Offset concern (https://www.excelbanter.com/excel-programming/357415-offset-concern.html)

Bri[_3_]

Offset concern
 
I'm having trouble modifying a line of code. As shown the code selects the
data in columns A:C from row 2 down the the last row with data in A. This
work fine.

Worksheets("Sheet1").Range("A2:C" & Range("A2").End(xlDown).Row).Select

Here's my problem. I need to keep offsetting this calculation by 4 columns
using an integer n. If n=1, the code is as above. If n=2, the code should
select the data in columns E:G from row 2 down the the last row with data in
E (that very last part about E is where I'm stuck).

I'd be grateful for help with this
Bri








Gary Keramidas

Offset concern
 
not sure what you mean, is this anywhere near what you want?

Dim lastrow As Long

Sub test()
lastrow = Cells(Rows.Count, Range("a2").Value).End(xlUp).Row
Worksheets("Sheet1").Range(Cells(2, 1 + Range("A2")), Cells(lastrow, 2 + _
Range("a2"))).Select
End Sub
--


Gary


"Bri" wrote in message
...
I'm having trouble modifying a line of code. As shown the code selects the
data in columns A:C from row 2 down the the last row with data in A. This
work fine.

Worksheets("Sheet1").Range("A2:C" & Range("A2").End(xlDown).Row).Select

Here's my problem. I need to keep offsetting this calculation by 4 columns
using an integer n. If n=1, the code is as above. If n=2, the code should
select the data in columns E:G from row 2 down the the last row with data in E
(that very last part about E is where I'm stuck).

I'd be grateful for help with this
Bri










Ken Johnson

Offset concern
 
Hi Bri,
Or this?
Dim n As Integer
For n = 0 To 5
Worksheets("Sheet1").Range("A2:C" & Range("A2"). _
End(xlDown).Row).Offset(0, n * 4).Select
Next

Which I guess does what you want for 4 offsets.

Ken Johnson


Bri[_3_]

Offset concern
 
Ken - Yes, that's it exactly. I had the 'offset' and the 'end' in the wrong
places.
Thanks, Bri

"Ken Johnson" wrote in message
oups.com...
Hi Bri,
Or this?
Dim n As Integer
For n = 0 To 5
Worksheets("Sheet1").Range("A2:C" & Range("A2"). _
End(xlDown).Row).Offset(0, n * 4).Select
Next

Which I guess does what you want for 4 offsets.

Ken Johnson




Ken Johnson

Offset concern
 
Hi Bri,
You're welcome, thanks for the feedback.
Ken Johnson



All times are GMT +1. The time now is 04:55 PM.

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