Excel VBA programming Tip

boris3006

New Member
Joined
Nov 1, 2005
Messages
1
Hi,

I am trying to teach myself to write a macro in VBA. I have run into a problem, and I am hoping somebody can help. I download a speadsheet with dates in col A, and hi, low, and close stock price in column b through d. I have written code (shown below) to ask the user to enter a date. I would like the macro to search for the cell of the date entered and then set a variable equal to the corresponsing price in column D of that row. I am having problems using variables properly in my code. Can somebody offer suggestions. Below is the code I have so far.

Sub NewFDAdrug()
Dim ApprovalDate
Dim Symbol
Dim PriceDayZero
Dim setRange
Dim setRangeFound
Symbol = InputBox("Enter the symbol of the stock")
ApprovalDate = InputBox("Enter the Date of Drug Approval by the FDA")
' I want to write code here that will search for cell the contains ApprovalDate_
' and then set PriceDayZero eqal to the price in column D of that row.

Thanks,
Bruce
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Welcome to the Board!

As you already seem to have a grasp of VBA, take a look at the "Find Method" in the VBA helpfile. You should be able to do what you want with .Find & Offset.

I'd offer more, but from your code, it looks like you want to match the Date and the Ticker, not just the date...?

Hope that helps,

Smitty

Note, if you know what they are, you'd be better of declaring your variables as more than just the Variant type (the default). I.E. Dim Symbol as String.
 
Upvote 0

Forum statistics

Threads
1,203,486
Messages
6,055,709
Members
444,809
Latest member
mwh85

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