VBA to extract data based on first occurrence in column; Trading Analysis

yousufj56

Board Regular
Joined
May 22, 2014
Messages
51
Hi,

I have an excel file with 1500 columns and each column has 4500 rows of data. Here is an example of what my spreadsheet looks like:

https://imgur.com/a/n9mZ7

Here is what i'm looking to do.

1. I want excel to look at every 4th column starting from B. So the first column excel would look at is column E.

2. From this 4th column, I want excel to retrieve the Column header (in the first row of that column).

3. Then, i want excel to look for the first occurrence of the word "Buy" in the column.

4. If a buy cell is found in the column, then retrieve the value of the column that is 3 columns to the left of the "Buy" cell.

5. In addition to that, I want the the corresponding value from that row but in Column A (i have the date there).

6. Then repeat the same thing for the word "Sell". Making sure that the "Sell" that is taken into consideration is the first "Sell" that has occurred in a row after "Buy". (not before the "Buy").

Essentially what I want to do is, get all the buy and sell points for given stocks so I could analyze to see if the signal is profitable or not.

Wondering if someone can help me figure this out?

Thanks
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
The code is case sensitive, so change Buy and Sell to BUY and SELL. I'll check the rest to be sure it's ok.
 
Upvote 0
Tested several lines at random, seems to work. (changed range("O1") at the end to BAQ1 of course)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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