View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Bill Bill is offline
external usenet poster
 
Posts: 390
Default Insert value of formula into cell

Steve

Thanks. Thank worked perfect. Can you look at the code for months two and
three. The months do not increase. I use to add a 1 or 2 depending but it
does not work. Thanks

'first month's code
Range("L1").Value = WorksheetFunction.VLookup(Month(Range("A4")), _
Sheets("Data").Range("A1:B14"), 2, False) & " " & Year(Range("A4"))
Range("L1").NumberFormat = "mmmm yyyy"

'second month's code
Dim MTH As Variant
MTH = Range("A4").Value
If MTH = 12 Then
Range("AQ1").Value = WorksheetFunction.VLookup(Month(Range("A4") +
1), _
Sheets("Data").Range("A1:B14"), 2, False) & " " & Year(Range("A4") +
1)
Range("AQ1").NumberFormat = "mmmm yyyy"
Else
Range("AQ1").Value = WorksheetFunction.VLookup(Month(Range("A4") +
1), _
Sheets("Data").Range("A1:B14"), 2, False) & " " & Year(Range("A4"))
Range("AQ1").NumberFormat = "mmmm yyyy"
End If

'third month's code
If MTH = 11 Or 12 Then
Range("BU1").Value = WorksheetFunction.VLookup(Month(Range("A4") +
2), _
Sheets("Data").Range("A1:B14"), 2, False) & " " & Year(Range("A4") +
1)
Range("BU1").NumberFormat = "mmmm yyyy"
Else
Range("BU1").Value = WorksheetFunction.VLookup(Month(Range("A4") +
2), _
Sheets("Data").Range("A1:B14"), 2, False) & " " & Year(Range("A4"))
Range("BU1").NumberFormat = "mmmm yyyy"
End If


"STEVE BELL" wrote:

Bll,

My oversight - forgot that you were writing code and didn't get all the
ranges set up for code:
[Note this should be on a single line, but the line continuation _ makes
Excel see it as one line; and you may not need ".Value"]

Range("A4").Value = WorksheetFunction.VLookup(Month(Range("A4")), _
Sheets("Data").Range("A1:B14"), 2, False) & " " & Year(Range("A4"))


Also - (not sure) but it looks like you just want Month Year in A4
If so - you can just format the cell
Range("A4").NumberFormat = "mmmm yyyy"
or
Range("A4").NumberFormat = "mmm yyyy"
--
steveB

Remove "AYN" from email to respond
"Bill" wrote in message
...
Steve & all

Thanks. I would appreciate any additional information you can provide. I
have not been able to get the code with the changes to work.

Bill

"STEVE BELL" wrote:

In code you need to specify ranges as
Range("A4")
so
Month(A4) should be Month(Range("A4")
Data!A1:B14 should be Sheets("Data").Range("A1:B14")
--
steveB

Remove "AYN" from email to respond
"Bill" wrote in message
...
The following code does not work. I am trying to put the result of the
formula into cell J7. Nothing happens.

Range("J7").Value = "VLookup(Month(A4), Data!A1:B14, 2, False)& " " &
YEAR(A4)

Thanks
Bill