Select EndDown, and then a further 2 rows

dannybland

New Member
Joined
Sep 12, 2014
Messages
31
I have the below code which selects all data below A5, includes the 17 columns on the right of it, and then offsets by one so I don't clear the title row.

<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">` Set wksdestination = Sheets("Continental")
Set registcell = wksdestination.Range("A5")
Set rngdata = Range(registcell.End(xlDown).Offset(0, 17), registcell.Offset(1, 0))
rngdata.Clear
`

</code>I also need it to clear the two rows below the end row as well as there are occasionally some SUM functions in the cells two below some of the columns. Can someone help with the last bit of adding the two rows below selection as well?
I tried

<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">`
Set
wksdestination = Sheets("Continental")
Set registcell = wksdestination.Range("A5")
Set rngdata = Range(registcell.End(xlDown).Offset(2, 17), registcell.Offset(1, 0))
rngdata.Clear
`

</code>But that gives a Run-time error '1004'

I have also tried the below, but it breaks if there is no data, and isn't ideal as it involves selecting the different sheets, would prefer if it ran without selecting each sheet, but if that's the only way then that'll have to do

<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">
Rich (BB code):
Set
Rich (BB code):
 wksdestination = Sheets("Continental")
Set registcell = wksdestination.Range("A5")
Set rngdata = Range(registcell.End(xlDown).Offset(0, 17), registcell.Offset(1, 0))
wksdestination.Select
Range(rngdata.Offset(2, 0), rngdata).Select
Selection.Clear

</code>Thanks
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
In case there is no date below A5 you can use End(xlUp) from the bottom of the column:

Code:
Sub TTTT()
    Set wksdestination = Sheets("Continental")
    With wksdestination
        Set registcell = .Range("A5")
        Set rngdata = .Range(.Cells(.Rows.Count, 1).End(xlUp).Offset(2, 17), registcell.Offset(1, 0))
    End With
    rngdata.Clear
End Sub
 
Upvote 0
It's giving a

Code:
Compile error:
Sub or Function not defined

And highlighting my sub name, I pasted the code in exactly as you put,

Code:
Sub CopyRegs()


    Dim wksdata As Worksheet
    Dim wksdestination As Worksheet
    Set wksdata = Sheets("Motivity Data")
    Dim rngdata As Range
    Dim rngdestination As Range
    Dim registcell As Range
    
'#################################################################################################


    Set wksdestination = Sheets("Continental")
    With wksdestination
        Set registcell = .Range("A5")
        Set rngdata = .Range(.Cells(.Rows.Count, 1).End(xlUp).Offset(2, 17), registcell.Offset(1, 0))
    End With
    rngdata.Clear
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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