Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default I need to use the last row of data in a formula

I'm writing a macro to calculate the coefficient and intercept of a log curve

the following is what the equation should look like in the cell:
=INDEX(LINEST('Expect Database Search'!$Q$3:$Q$90,LN('Expect Database
Search'!$G$3:$G$90)),1,1)

however in VB I have to write it in this format:
Range("B2").Formula = "=INDEX(LINEST('Expect Database
Search'!R3C17:R90C17,LN('Expect Database Search'!R3C7:R90C7)),1,1)"

My problem is that the data set is never the same so I may have 100 rows or
1000 or anything in between. Is there a way to write this so that the
formula will find the last row of data and use that row number instead?

I've found examples of how to find the last row and the following is what I
have used in my code:
Dim LastRow As Long
Sheets("Expect Database Search").Select
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

but how do I now use this is my formula?

thank you for any insight you may provide
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default I need to use the last row of data in a formula

Dim lngRow As Long
lngRow = Cells(Rows.Count, "A").End(xlUp).Row

Range("B2").Formula = "=INDEX(LINEST('Expect Database Search'!$Q$3:$Q$" & _
lngRow & ",LN('Expect Database Search'!$G$3:$G$" & lngRow & ")),1,1)"


--
Jacob (MVP - Excel)


"vero" wrote:

I'm writing a macro to calculate the coefficient and intercept of a log curve

the following is what the equation should look like in the cell:
=INDEX(LINEST('Expect Database Search'!$Q$3:$Q$90,LN('Expect Database
Search'!$G$3:$G$90)),1,1)

however in VB I have to write it in this format:
Range("B2").Formula = "=INDEX(LINEST('Expect Database
Search'!R3C17:R90C17,LN('Expect Database Search'!R3C7:R90C7)),1,1)"

My problem is that the data set is never the same so I may have 100 rows or
1000 or anything in between. Is there a way to write this so that the
formula will find the last row of data and use that row number instead?

I've found examples of how to find the last row and the following is what I
have used in my code:
Dim LastRow As Long
Sheets("Expect Database Search").Select
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

but how do I now use this is my formula?

thank you for any insight you may provide

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default I need to use the last row of data in a formula

Hi,

Maybe this way

Dim LastRow As Long
Set sht = Sheets("Expect Database Search")

LastRow = sht.Cells(Rows.Count, "Q").End(xlUp).Row
sht.Range("B2").Formula = _
"=INDEX(LINEST('Expect Database Search'!$Q$3:$Q$" & _
LastRow & ",LN('Expect Database Search'!$G$3:$G$" & LastRow & ")),1,1)"

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"vero" wrote:

I'm writing a macro to calculate the coefficient and intercept of a log curve

the following is what the equation should look like in the cell:
=INDEX(LINEST('Expect Database Search'!$Q$3:$Q$90,LN('Expect Database
Search'!$G$3:$G$90)),1,1)

however in VB I have to write it in this format:
Range("B2").Formula = "=INDEX(LINEST('Expect Database
Search'!R3C17:R90C17,LN('Expect Database Search'!R3C7:R90C7)),1,1)"

My problem is that the data set is never the same so I may have 100 rows or
1000 or anything in between. Is there a way to write this so that the
formula will find the last row of data and use that row number instead?

I've found examples of how to find the last row and the following is what I
have used in my code:
Dim LastRow As Long
Sheets("Expect Database Search").Select
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

but how do I now use this is my formula?

thank you for any insight you may provide

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default I need to use the last row of data in a formula

Thank you Jacob & Mike, it works perfect!

"vero" wrote:

I'm writing a macro to calculate the coefficient and intercept of a log curve

the following is what the equation should look like in the cell:
=INDEX(LINEST('Expect Database Search'!$Q$3:$Q$90,LN('Expect Database
Search'!$G$3:$G$90)),1,1)

however in VB I have to write it in this format:
Range("B2").Formula = "=INDEX(LINEST('Expect Database
Search'!R3C17:R90C17,LN('Expect Database Search'!R3C7:R90C7)),1,1)"

My problem is that the data set is never the same so I may have 100 rows or
1000 or anything in between. Is there a way to write this so that the
formula will find the last row of data and use that row number instead?

I've found examples of how to find the last row and the following is what I
have used in my code:
Dim LastRow As Long
Sheets("Expect Database Search").Select
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

but how do I now use this is my formula?

thank you for any insight you may provide

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
Formula to sum data from a data range mike the new guy Excel Discussion (Misc queries) 3 January 18th 06 08:56 AM
Formula to capture historical data from data that changes daily DKennedy Excel Discussion (Misc queries) 0 December 28th 05 08:24 PM
Formula to capture historical data from data that changes daily DKennedy Excel Worksheet Functions 0 December 28th 05 08:23 PM
Any cell containing formula seen as data instead of formula Jeffry61 Excel Worksheet Functions 2 September 23rd 05 02:04 PM
DATA VALIDATION - for data which is the result of a formula Gator Girl Excel Programming 5 September 12th 05 07:06 PM


All times are GMT +1. The time now is 01:21 AM.

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"