Set Range offset issue

Ray805

New Member
Joined
Sep 29, 2010
Messages
22
hi,
i cant seem to get this one right....
what im trying to do is fill column S-T-U with a list in column A.
i need the bottom 80 from the list to go to column U, then the next 80 before that to go to column T, then the remainder go to column S.

this is what i have so far, now it copys to column S fine with the correct amount it needs to but iv run into a problem trying to set the range of the next 80

Code:
'count list in column A
    Dim myRng As Range
    Dim nResult As Long
    Dim LASTR As Long
        LASTR = Range("A65536").End(xlUp).Row
        Set myRng = Range("A2:A" & LASTR)
        nResult = WorksheetFunction.CountA(myRng)
        
'set range of col-1 and copy
    Dim oneLR As Variant
    Dim oneGRange As Range
        oneLR = (nResult - 159)
        Set oneGRange = Range("A2:A" & oneLR)
        oneGRange.Copy
        Range("S1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'set range of col-2 and copy
    Dim twoGRange As Range
    Dim twoFR As Long
    Dim twoLR As Long
        twoFR = oneLR.Offset(1, 0)
        twoLR = oneLR.Offset(81, 0)
        Set twoGRange = Range(twoFR, twoLR)
        twoGRange.Copy
        Range("T1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'set range of col-3 and copy
    Dim threeGRange As Range
    Dim threeFR As Long
    Dim threeLR As Long
        threeFR = twoLR.Offset(1, 0)
        threeLR = twoLR.Offset(81, 0)
        Set threeGRange = Range(threeFR, threeLR)
        threeGRange.Copy
        Range("U1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
im not too sure what im doing wrong.
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

s hal

Board Regular
Joined
Apr 10, 2013
Messages
198
I would approach this a different way. I don't know how many items are in your column, but if you want the bottom 160 to go in two columns and the rest to go in a third, I'd suggest counting what the total is at the beginning rather than three times and doing something like the following (not testing this code, so let me know if you run into problems): (and apologizing as I'm not sure how to do the code box on this forum)

Sub ()
Dim Length as Long
Length = WorksheetFunction.CountA(Range(Cells(1, 1), Cells(1, 1).End(xlDown)))
Range(Cells(Length - 79, 1), Cells(Length, 1)).Copy
Range("U1").PasteSpecial Paste:=xlValues
Range(Cells(Length - 159, 1), Cells(Length - 80, 1)).Copy
Range("T1").PasteSpecial Paste:=xlValues
Range(Cells(1, 1), Cells(Length - 160, 1)).Copy
Range("S1").PasteSpecial Paste:=xlValues
End Sub

Hope this helps!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,271
Messages
5,600,646
Members
414,398
Latest member
dhune

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
Top