Dynamic Vlookup

mike92500

New Member
Joined
May 21, 2012
Messages
1
Hello all, I am new to VBA and really trying to improve. I tried looking a solution up, but couldn't really find what I need. Can anyone help me? or have an idea would be great! I really appreciate it!

I can't attach the xls, but here is how its presented:
Column A has the daily dates, column D has the month and column E has the price corresponding to the month.

Column A ColumnD (doesn't really matter) ColumnE
5/21/2012 Bal May -1.3
5/22/2012 June -1.0
5/23/2012 Jul -0.65
etc.... Aug etc....
3q 12
4q 12

So I need to match the prices (column E) with the days of that month (column A) and put the prices in column B, so Bal May price -1.3 would be attached to all the days of May, and q3 12 would be attached to all the days in Sep, and 4q 12 would be attached to all the days of October, November, December...
What I coded was basically, return the number of the month of date, so 5/21/2012 would return 5, and then look in the column D for month 5 and return with a Vlookup the price in column E (-1.3).
My problem comes with 1q, 2q, 3q and 4q....because basically I need some code to search in this example "Sep" not find it, and return 3q 12 price, but also need to search Oct, Nov, and Dec and retun the 4q 12 price. The problem is that at one point in time the Oct price won't be 4q 12 anymore, etc....So my Vlookup is stuck there.....Here is my code below....If u have just an idea as to what I should be trying to do, that would be GREAT!! THANKS A LOT!

Public Sub vlookup()

'this looks up for a month, and returns the corresponding number of the month

For count = 7 To 415
Set monthCell = Worksheets("Price curve").Cells(count, 17)
Set dateCell = Worksheets("Price curve").Cells(count, 1)

If monthCell.Value = "Jan" Then monthCell.Offset(0, -1).Value = 1
If monthCell.Value = "Bal Jan" Then monthCell.Offset(0, -1).Value = 1
If monthCell.Value = "Feb" Then monthCell.Offset(0, -1).Value = 2
If monthCell.Value = "Bal Feb" Then monthCell.Offset(0, -1).Value = 2
If monthCell.Value = "Mar" Then monthCell.Offset(0, -1).Value = 3
If monthCell.Value = "Bal Mar" Then monthCell.Offset(0, -1).Value = 3
If monthCell.Value = "Apr" Then monthCell.Offset(0, -1).Value = 4
If monthCell.Value = "Bal Apr" Then monthCell.Offset(0, -1).Value = 4
If monthCell.Value = "May" Then monthCell.Offset(0, -1).Value = 5
If monthCell.Value = "Bal May" Then monthCell.Offset(0, -1).Value = 5
If monthCell.Value = "June" Then monthCell.Offset(0, -1).Value = 6
If monthCell.Value = "Bal June" Then monthCell.Offset(0, -1).Value = 6
If monthCell.Value = "July" Then monthCell.Offset(0, -1).Value = 7
If monthCell.Value = "Bal July" Then monthCell.Offset(0, -1).Value = 7
If monthCell.Value = "Aug" Then monthCell.Offset(0, -1).Value = 8
If monthCell.Value = "Bal Aug" Then monthCell.Offset(0, -1).Value = 8
If monthCell.Value = "Sep" Then monthCell.Offset(0, -1).Value = 9
If monthCell.Value = "Bal Sep" Then monthCell.Offset(0, -1).Value = 9
If monthCell.Value = "Oct" Then monthCell.Offset(0, -1).Value = 10
If monthCell.Value = "Bal Oct" Then monthCell.Offset(0, -1).Value = 10
If monthCell.Value = "Nov" Then monthCell.Offset(0, -1).Value = 11
If monthCell.Value = "Bal Nov" Then monthCell.Offset(0, -1).Value = 11
If monthCell.Value = "Dec" Then monthCell.Offset(0, -1).Value = 12
If monthCell.Value = "Bal Dec" Then monthCell.Offset(0, -1).Value = 12

dateCell.Offset(0, 1) = Application.vlookup(Month(dateCell), Range("P7:S24"), 4, False)

'I tried the below to solve my pb, but it doesn't since Aug value 10, takes over Sep value...'

If monthCell.Value <> "Sep" And monthCell.Value <> "Bal Sep" And monthCell.Value = "3q 12" Then monthCell.Offset(0, -1).Value = 9
If monthCell.Value <> "Aug" And monthCell.Value <> "Bal Aug" And monthCell.Value = "3q 12" Then monthCell.Offset(0, -1).Value = 10


Next count

End Sub
 

Forum statistics

Threads
1,081,971
Messages
5,362,492
Members
400,677
Latest member
champchamp

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top