quick VBA question on selection

deletedalien

Well-known Member
Joined
Dec 8, 2008
Messages
505
Office Version
  1. 2013
Platform
  1. Windows
So i know that the lines in red are wrong because they do random things every time i run this code, and i can't remember how to do this

First error line
i want to select from row 2 columns A:V and all the way down and delete that data (but sometimes it also deletes whats in column W.....

The second error line
only selects rows 4 & 5 from columns A:V....



Rich (BB code):
Sub Centris()


    ActiveSheet.Previous.Select
    Range("A2:V2", Selection.End(xlDown)).ClearContents
    
    Selection.End(xlToLeft).Select
    
    ActiveWindow.ActivateNext
    
    Range("A5:V5", Selection.End(xlDown)).copy
    
    ActiveWindow.ActivateNext
    
    Range("A2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Application.CutCopyMode = False
    ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
    
End Sub

Thankx in advance for any help given.
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,679
Office Version
  1. 2010
Platform
  1. Windows
First error line
i want to select from row 2 columns A:V and all the way down and delete that data (but sometimes it also deletes whats in column W.....
Rich (BB code):
    Range("A2:V2", Selection.End(xlDown)).ClearContents
Assuming Column A contains data in the last row with data in Columns A:V...
Code:
Range("A2:V" & Cells(Rows.Count, "A").End(xlUp).Row).ClearContents


The second error line
only selects rows 4 & 5 from columns A:V....
Rich (BB code):
    Range("A5:V5", Selection.End(xlDown)).copy
Assuming Column A contains data in the last row with data in Columns A:V...
Code:
Range("A5:V" & Cells(Rows.Count, "A").End(xlUp).Row).Copy
 
Solution

deletedalien

Well-known Member
Joined
Dec 8, 2008
Messages
505
Office Version
  1. 2013
Platform
  1. Windows
Brilliant as always...

Thank you VERY much!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,315
Members
414,053
Latest member
Dual Showman

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