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

Hello all,
I have a little predicament where I had a large spreadsheet that
would take values from other sheets and insert them into the last row.
Everything worked fine, but the person organizing the little project
changed the requirements on me last second and decided it would be
better to have a formula in each cell referencing the files rather than
have the values. The easiest way to do this would be to make a string
representing the formula (it requires concatenation of three different
things) and then put that into the the cell. However, this is where
things get tricky for me. I vaguely know of a eval() method to make a
formula from a string, but Im not sure if this would work in a
lastrow.offset(1,0) = <insert code here type of situation.

Heres a snippet of the original code that would need to be changed

Dim lastrow as object
Dim surveyWorkbook as Workbook, currentWorkbook as Workbook
Dim surveyWS as Worksheet

..
..
..
With currentWorkbook
Set Lastrow = Sheet1.Range("a65536").End(xlUp)
'write the data to the new sheets
Lastrow.Offset(1, 0) = surveyWorkbook.Name
Lastrow.Offset(1, 1) = surveyWS.Range("b4").Value
Lastrow.Offset(1, 2) = surveyWS.Range("b5").Value

End With


I would have a ready made concatonated string with the formula, the
last row set, and now all that would remain would be to find a way to
get that formula into all the correct cells. If you know of a way to do
this. Or if the answer is so simple its staring me in the face, feel
free to be the first to let me know.(with a solution of course)

Thank you for any help in advance,
Rob

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,081
Default Insert a formula into the last row of a cell

something along the lines of

Lastrow.Offset(1, 1).formula = "='" & surveyWS.name & "'!b4"


"RoVo" wrote:

Hello all,
I have a little predicament where I had a large spreadsheet that
would take values from other sheets and insert them into the last row.
Everything worked fine, but the person organizing the little project
changed the requirements on me last second and decided it would be
better to have a formula in each cell referencing the files rather than
have the values. The easiest way to do this would be to make a string
representing the formula (it requires concatenation of three different
things) and then put that into the the cell. However, this is where
things get tricky for me. I vaguely know of a eval() method to make a
formula from a string, but Im not sure if this would work in a
lastrow.offset(1,0) = <insert code here type of situation.

Heres a snippet of the original code that would need to be changed

Dim lastrow as object
Dim surveyWorkbook as Workbook, currentWorkbook as Workbook
Dim surveyWS as Worksheet

..
..
..
With currentWorkbook
Set Lastrow = Sheet1.Range("a65536").End(xlUp)
'write the data to the new sheets
Lastrow.Offset(1, 0) = surveyWorkbook.Name
Lastrow.Offset(1, 1) = surveyWS.Range("b4").Value
Lastrow.Offset(1, 2) = surveyWS.Range("b5").Value

End With


I would have a ready made concatonated string with the formula, the
last row set, and now all that would remain would be to find a way to
get that formula into all the correct cells. If you know of a way to do
this. Or if the answer is so simple its staring me in the face, feel
free to be the first to let me know.(with a solution of course)

Thank you for any help in advance,
Rob


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default Insert a formula into the last row of a cell

I think its some like this:

With currentWorkbook
Set Lastrow = Sheet1.Range("a65536").End(xlUp)
'write the data to the new sheets
Lastrow.Offset(1, 0) = surveyWorkbook.Name
Lastrow.Offset(1, 1).Formula = "surveyWS!b4"
Lastrow.Offset(1, 2).Formula = "surveyWS!b5"

End With

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
Insert Formula in Cell with VBA Ctech[_137_] Excel Programming 1 April 5th 06 11:27 AM
Using VBA to Insert a formula in a cell Lee Excel Programming 2 March 17th 06 01:23 AM
Insert value of formula into cell Bill Excel Programming 16 August 1st 05 06:16 PM
insert formula in last cell J_Gold Excel Programming 6 May 31st 05 03:14 AM


All times are GMT +1. The time now is 04:35 PM.

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

About Us

"It's about Microsoft Excel"