Clear a range of all data after a certain date obtained from another worksheet

pbinvestor

New Member
Joined
Apr 14, 2002
Messages
19
I have a spreadsheet that has about 15 columns of stock data sorted from most recent going back years.
Some stocks have no history before a certain date.
Since I am comparing each stock to each other one I need to eliminate all data that falls befpre the stock with the least amount of data.

So what I am looking for is if I identify the shortest stock history as only 4 years and my longest might be 20 years I want to truncate my table by clearing all data from all stock columns that occured before that date.

I don't want to delete the rows because I have other processes in columns to the right of the last column.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Title should have read "before a certain date"
I have already identified the shortest data column in the sheet. JUst need vba to select all columns before that date and clear them.
Thanks...Stupid little problem I know but got hung up on it.
 
Upvote 0
Not much to go on but you could simply loop thru the data and clear the cell contents if the data was less than your 'certain date'. Here's a snippet of code that might be useful, we'll assume your dates are in column A1 down and your stock data in A:D columns. For the example just stick the date in cell E1 but obviously you can substitute that with whatever code you use to find the certain date and add extra code to re-sort the data if needed.

Code:
Sub ClearRows()
    Dim i As Long
    Dim LRow As Long
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    LRow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To LRow
    If Range("A" & i).Value < Range("E1").Value Then Range("A" & i & ":D" & i).ClearContents
    Next i
    
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True




End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

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