Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Insert value of formula into cell

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Insert value of formula into cell

Hi,

If you want to use VLookup (or any worksheet formula) in your code you need
to use the WorksheetFunction object

e.g,

Range("J7").Value = WorksheetFunction.VLookup( <Arguments go here)

HTH,
Matt



"Bill" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Insert value of formula into cell

Hi,

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

HTH

"Matt Lunn" wrote:

Hi,

If you want to use VLookup (or any worksheet formula) in your code you need
to use the WorksheetFunction object

e.g,

Range("J7").Value = WorksheetFunction.VLookup( <Arguments go here)

HTH,
Matt



"Bill" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Insert value of formula into cell

Range("J7").Value = "VLookup(Month(A4), Data!A1:B14, 2, False)& " " &
YEAR(A4)
you have to use syntax that excel understands for vba
Range("J7").Value = application.VLookup(Month(range("A4"),etc
or put in the formula
Range("J7").formula = "=VLookup(Month(A4), Data!A1:B14, 2, False)& " " &
YEAR(A4)"
and then
Range("J7").value=Range("J7").value



--
Don Guillett
SalesAid Software

"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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Insert value of formula into cell

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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Insert value of formula into cell

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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Insert value of formula into cell

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






  #8   Report Post  
Posted to microsoft.public.excel.programming
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






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Insert value of formula into cell

Bill,

Just a couple of minor changes:
Since it appears that MTH appears to be a number between 1 & 12, and A4
appears to be a date,
than MTH = Month(Range("A4"))
if MTH = Range("A4") it will end up being something like 38265 (the way
Excel sees a date)

If you want to write an "OR" statement, it is

If MTH = x OR MTH = y then ............

And remember that
Range("A4").Value is the same as Range("A4")
not very important but anytime you can remove a "." the code gets a little
faster....
becomes serious when your code gets long and complex.

Added a couple of variables to make the formulas a little simpler... and
remove repeat calculations.
(There are a few ways to make it even simpler - but catch up to this
first...)

don't dim variables as variant unless absolutely necessary - slows code and
uses more memory.
Since MTH runs from 1 - 14 it is easier to call it an Integer. YR is also
an Integer. And rng is
an object and needs to be "Set".

(You could also use MTH2 = MTH +2, YR2 = YR + 1) - but not important...

=======================================
Dim MTH As Integer, YR As Integer, rng As Range

MTH = Month(Range("A4"))
YR = Year(Range("A4"))
Set rng = Sheets("Data").Range("A1:B14")

'first month's code
Range("L1") = WorksheetFunction.VLookup(MTH, rng, 2, False) & " " & YR
Range("L1").NumberFormat = "mmmm yyyy"

'second month's code
If MTH = 12 Then
Range("AQ1") = WorksheetFunction.VLookup(MTH + 1, rng, 2, False) & "
" & YR + 1
Range("AQ1").NumberFormat = "mmmm yyyy"
Else
Range("AQ1") = WorksheetFunction.VLookup(MTH + 1, rng, 2, False) & "
" & YR
Range("AQ1").NumberFormat = "mmmm yyyy"
End If

'third month's code
If MTH = 11 Or MTH = 12 Then
Range("BU1") = WorksheetFunction.VLookup(MTH + 2, rng, 2, False) & "
" & YR + 1
Range("BU1").NumberFormat = "mmmm yyyy"
Else
Range("BU1") = WorksheetFunction.VLookup(MTH + 2, rng, 2, False) & "
" & YR
Range("BU1").NumberFormat = "mmmm yyyy"
End If
=========================================

--
steveB

Remove "AYN" from email to respond
"Bill" wrote in message
...
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








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert text from one cell into formula in another cell. Deserthawk99 Excel Discussion (Misc queries) 2 March 1st 08 05:02 PM
Maintaining a formula in a cell when there was an insert row Devin Excel Discussion (Misc queries) 2 March 10th 06 07:15 PM
insert formula in last cell J_Gold Excel Programming 6 May 31st 05 03:14 AM
insert a new cell into an existing formula Debbie Excel Discussion (Misc queries) 3 March 14th 05 06:46 PM
Insert variable cell in the formula Gian Excel Programming 5 February 7th 05 07:23 PM


All times are GMT +1. The time now is 11:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"