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.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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
 
Upvote 0
Solution

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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