Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default replacing value by formula


HI,

My column heading (Y9:AF9) a
Mar-04 Apr-04 May-04 Jun-04 Q4 2004 Q1 2005 Year 2004 Sum
Year 2005
Sum

I have to have a YEar SUm of 2004 and 2005, which i am
doing by the code
below. With this logic i am getting the final value and
formala. Instead of
this logic I want to have =SUM(Y10:AC10) in each cell.
Before having a total
I want to check whether it lies in 2004 or 2005. IS it
possible to replace
the cell value by the formula as =SUM(Y10:AC10)?

thanks in advance
monika

'INSERTING VALUES FOR YEARLY SUM'S COLUMNS
Dim sysYr, fSumYr1, fSumYr2 As Long
Dim QYR As Long
sysYr = Year(Date)
j = LNewRng.Row + 1
k = LNewRng.Row

While j <= LastCellNum
i = lastCol + 1 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr1 = 0 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr2 = 0 'REINITIALIZING FOR EVERY
NEW ROW
While i <= colEnd
If IsDate(Cells(k, i).Value) = True Then
'SUM FOR DATE CASES
yr1 = Year(Cells(k, i).Value)
If yr1 = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
'Stop
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
ElseIf Mid(Cells(k, i).Value, 1, 1) = "Q" Then
'QUARTER SUM CALCULATION
QYR = Right(Cells(k, i).Value, 4)
If QYR = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
End If
i = i + 1
Wend
Cells(j, colEnd).Value = fSumYr1
Cells(j, colEnd + 1).Value = fSumYr2
j = j + 1
Wend

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default replacing value by formula

Hi Monika,

Struggling a bit to see what is happening without any data, but is this what
you want

Cells(j, colEnd).FormulaR1C1 = "=SUMPRODUCT(--(RC" & lastCol & ":RC"
& colEnd - 1 & ")=" & sysYr & ")"
Cells(j, colEnd + 1).FormulaR1C1 = "=SUMPRODUCT((LEFT(RC" & lastCol
& ":RC" & colEnd - 1 & ",1)=""Q"")*" & _
"(RIGHT(RC" & lastCol & ":RC" &
colEnd - 1 & ",4)=""" & sysYr & """))"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"monika" wrote in message
...

HI,

My column heading (Y9:AF9) a
Mar-04 Apr-04 May-04 Jun-04 Q4 2004 Q1 2005 Year 2004 Sum
Year 2005
Sum

I have to have a YEar SUm of 2004 and 2005, which i am
doing by the code
below. With this logic i am getting the final value and
formala. Instead of
this logic I want to have =SUM(Y10:AC10) in each cell.
Before having a total
I want to check whether it lies in 2004 or 2005. IS it
possible to replace
the cell value by the formula as =SUM(Y10:AC10)?

thanks in advance
monika

'INSERTING VALUES FOR YEARLY SUM'S COLUMNS
Dim sysYr, fSumYr1, fSumYr2 As Long
Dim QYR As Long
sysYr = Year(Date)
j = LNewRng.Row + 1
k = LNewRng.Row

While j <= LastCellNum
i = lastCol + 1 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr1 = 0 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr2 = 0 'REINITIALIZING FOR EVERY
NEW ROW
While i <= colEnd
If IsDate(Cells(k, i).Value) = True Then
'SUM FOR DATE CASES
yr1 = Year(Cells(k, i).Value)
If yr1 = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
'Stop
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
ElseIf Mid(Cells(k, i).Value, 1, 1) = "Q" Then
'QUARTER SUM CALCULATION
QYR = Right(Cells(k, i).Value, 4)
If QYR = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
End If
i = i + 1
Wend
Cells(j, colEnd).Value = fSumYr1
Cells(j, colEnd + 1).Value = fSumYr2
j = j + 1
Wend



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default replacing value by formula

Hi Bob,

i am not able to understand your code properly.
I want year 2004 sum to be in "Year Sum 2004" Column and year 2005 sum to be
in year sum 2005 column. In my current rolling forecast for the month March
i have following column Headings:

Mar-04 Apr-04 May-04 Jun-04 Q4 2004 Q1 2005 Year 2004 Sum Year
2005 Sum


so my columns headings from mar-04 to may-04 are in date format. But Q4 2004
and Q5 2001 are not in date format. So what i am doing is first checking if
the column heading is a date then I further check is its a current or next
year. As these month will change with years in coming time.

So ifs its current year (2004) then i want the sum to be in year 2004 Sum
column heading. So i want total of columns which has 2004 volumes. Now in
this case i have to Q4 2004... which is not a date. so i check if the 1st
letter is "Q"; if yes then i check last 4 letters...its its current year
then i have to add the total in year sum 2004.

and if its 2005 then in year sum 2005 column. In this case I have only one
2005 column.

I hope this is feasible?

thanks tremendously
Monika


"Bob Phillips" wrote in message
...
Hi Monika,

Struggling a bit to see what is happening without any data, but is this

what
you want

Cells(j, colEnd).FormulaR1C1 = "=SUMPRODUCT(--(RC" & lastCol &

":RC"
& colEnd - 1 & ")=" & sysYr & ")"
Cells(j, colEnd + 1).FormulaR1C1 = "=SUMPRODUCT((LEFT(RC" &

lastCol
& ":RC" & colEnd - 1 & ",1)=""Q"")*" & _
"(RIGHT(RC" & lastCol & ":RC" &
colEnd - 1 & ",4)=""" & sysYr & """))"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"monika" wrote in message
...

HI,

My column heading (Y9:AF9) a
Mar-04 Apr-04 May-04 Jun-04 Q4 2004 Q1 2005 Year 2004 Sum
Year 2005
Sum

I have to have a YEar SUm of 2004 and 2005, which i am
doing by the code
below. With this logic i am getting the final value and
formala. Instead of
this logic I want to have =SUM(Y10:AC10) in each cell.
Before having a total
I want to check whether it lies in 2004 or 2005. IS it
possible to replace
the cell value by the formula as =SUM(Y10:AC10)?

thanks in advance
monika

'INSERTING VALUES FOR YEARLY SUM'S COLUMNS
Dim sysYr, fSumYr1, fSumYr2 As Long
Dim QYR As Long
sysYr = Year(Date)
j = LNewRng.Row + 1
k = LNewRng.Row

While j <= LastCellNum
i = lastCol + 1 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr1 = 0 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr2 = 0 'REINITIALIZING FOR EVERY
NEW ROW
While i <= colEnd
If IsDate(Cells(k, i).Value) = True Then
'SUM FOR DATE CASES
yr1 = Year(Cells(k, i).Value)
If yr1 = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
'Stop
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
ElseIf Mid(Cells(k, i).Value, 1, 1) = "Q" Then
'QUARTER SUM CALCULATION
QYR = Right(Cells(k, i).Value, 4)
If QYR = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
End If
i = i + 1
Wend
Cells(j, colEnd).Value = fSumYr1
Cells(j, colEnd + 1).Value = fSumYr2
j = j + 1
Wend





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default replacing value by formula

Hi Monika,

What I did was post some code to dynamically create formulae for adding it
up. Is this not what you wanted, do you just want the sum in the cell rather
than a formula?

Can you post some data and explain what LNewRng is and where it gets set,
colEnd, and LastCellNum?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"monika" wrote in message
...
Hi Bob,

i am not able to understand your code properly.
I want year 2004 sum to be in "Year Sum 2004" Column and year 2005 sum to

be
in year sum 2005 column. In my current rolling forecast for the month

March
i have following column Headings:

Mar-04 Apr-04 May-04 Jun-04 Q4 2004 Q1 2005 Year 2004 Sum

Year
2005 Sum


so my columns headings from mar-04 to may-04 are in date format. But Q4

2004
and Q5 2001 are not in date format. So what i am doing is first checking

if
the column heading is a date then I further check is its a current or next
year. As these month will change with years in coming time.

So ifs its current year (2004) then i want the sum to be in year 2004 Sum
column heading. So i want total of columns which has 2004 volumes. Now in
this case i have to Q4 2004... which is not a date. so i check if the 1st
letter is "Q"; if yes then i check last 4 letters...its its current year
then i have to add the total in year sum 2004.

and if its 2005 then in year sum 2005 column. In this case I have only one
2005 column.

I hope this is feasible?

thanks tremendously
Monika


"Bob Phillips" wrote in message
...
Hi Monika,

Struggling a bit to see what is happening without any data, but is this

what
you want

Cells(j, colEnd).FormulaR1C1 = "=SUMPRODUCT(--(RC" & lastCol &

":RC"
& colEnd - 1 & ")=" & sysYr & ")"
Cells(j, colEnd + 1).FormulaR1C1 = "=SUMPRODUCT((LEFT(RC" &

lastCol
& ":RC" & colEnd - 1 & ",1)=""Q"")*" & _
"(RIGHT(RC" & lastCol & ":RC"

&
colEnd - 1 & ",4)=""" & sysYr & """))"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"monika" wrote in message
...

HI,

My column heading (Y9:AF9) a
Mar-04 Apr-04 May-04 Jun-04 Q4 2004 Q1 2005 Year 2004 Sum
Year 2005
Sum

I have to have a YEar SUm of 2004 and 2005, which i am
doing by the code
below. With this logic i am getting the final value and
formala. Instead of
this logic I want to have =SUM(Y10:AC10) in each cell.
Before having a total
I want to check whether it lies in 2004 or 2005. IS it
possible to replace
the cell value by the formula as =SUM(Y10:AC10)?

thanks in advance
monika

'INSERTING VALUES FOR YEARLY SUM'S COLUMNS
Dim sysYr, fSumYr1, fSumYr2 As Long
Dim QYR As Long
sysYr = Year(Date)
j = LNewRng.Row + 1
k = LNewRng.Row

While j <= LastCellNum
i = lastCol + 1 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr1 = 0 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr2 = 0 'REINITIALIZING FOR EVERY
NEW ROW
While i <= colEnd
If IsDate(Cells(k, i).Value) = True Then
'SUM FOR DATE CASES
yr1 = Year(Cells(k, i).Value)
If yr1 = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
'Stop
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
ElseIf Mid(Cells(k, i).Value, 1, 1) = "Q" Then
'QUARTER SUM CALCULATION
QYR = Right(Cells(k, i).Value, 4)
If QYR = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
End If
i = i + 1
Wend
Cells(j, colEnd).Value = fSumYr1
Cells(j, colEnd + 1).Value = fSumYr2
j = j + 1
Wend







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default replacing value by formula

LNewRng is the row where i need to start putting in the values. Like the
column headings are in the 9th row. So in my case lNewrng.row will be the
10th row. I set this value in the beginning of my logic.

lastCellnum is the last cell of the sheet. In my case its 293. I run the
loop till the last cell of the sheet.

colEnd here is the "Year Sum 2004" column number
colEnd + 1 is hte "Year Sum 2005" Column Number

I can pass u the data if u need further??? I hope i am clear

Thanks
Monika
"Bob Phillips" wrote in message
...
Hi Monika,

What I did was post some code to dynamically create formulae for adding it
up. Is this not what you wanted, do you just want the sum in the cell

rather
than a formula?

Can you post some data and explain what LNewRng is and where it gets set,
colEnd, and LastCellNum?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"monika" wrote in message
...
Hi Bob,

i am not able to understand your code properly.
I want year 2004 sum to be in "Year Sum 2004" Column and year 2005 sum

to
be
in year sum 2005 column. In my current rolling forecast for the month

March
i have following column Headings:

Mar-04 Apr-04 May-04 Jun-04 Q4 2004 Q1 2005 Year 2004 Sum

Year
2005 Sum


so my columns headings from mar-04 to may-04 are in date format. But Q4

2004
and Q5 2001 are not in date format. So what i am doing is first checking

if
the column heading is a date then I further check is its a current or

next
year. As these month will change with years in coming time.

So ifs its current year (2004) then i want the sum to be in year 2004

Sum
column heading. So i want total of columns which has 2004 volumes. Now

in
this case i have to Q4 2004... which is not a date. so i check if the

1st
letter is "Q"; if yes then i check last 4 letters...its its current year
then i have to add the total in year sum 2004.

and if its 2005 then in year sum 2005 column. In this case I have only

one
2005 column.

I hope this is feasible?

thanks tremendously
Monika


"Bob Phillips" wrote in message
...
Hi Monika,

Struggling a bit to see what is happening without any data, but is

this
what
you want

Cells(j, colEnd).FormulaR1C1 = "=SUMPRODUCT(--(RC" & lastCol &

":RC"
& colEnd - 1 & ")=" & sysYr & ")"
Cells(j, colEnd + 1).FormulaR1C1 = "=SUMPRODUCT((LEFT(RC" &

lastCol
& ":RC" & colEnd - 1 & ",1)=""Q"")*" & _
"(RIGHT(RC" & lastCol &

":RC"
&
colEnd - 1 & ",4)=""" & sysYr & """))"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"monika" wrote in message
...

HI,

My column heading (Y9:AF9) a
Mar-04 Apr-04 May-04 Jun-04 Q4 2004 Q1 2005 Year 2004 Sum
Year 2005
Sum

I have to have a YEar SUm of 2004 and 2005, which i am
doing by the code
below. With this logic i am getting the final value and
formala. Instead of
this logic I want to have =SUM(Y10:AC10) in each cell.
Before having a total
I want to check whether it lies in 2004 or 2005. IS it
possible to replace
the cell value by the formula as =SUM(Y10:AC10)?

thanks in advance
monika

'INSERTING VALUES FOR YEARLY SUM'S COLUMNS
Dim sysYr, fSumYr1, fSumYr2 As Long
Dim QYR As Long
sysYr = Year(Date)
j = LNewRng.Row + 1
k = LNewRng.Row

While j <= LastCellNum
i = lastCol + 1 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr1 = 0 'REINITIALIZING FOR EVERY
NEW ROW
fSumYr2 = 0 'REINITIALIZING FOR EVERY
NEW ROW
While i <= colEnd
If IsDate(Cells(k, i).Value) = True Then
'SUM FOR DATE CASES
yr1 = Year(Cells(k, i).Value)
If yr1 = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
'Stop
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
ElseIf Mid(Cells(k, i).Value, 1, 1) = "Q" Then
'QUARTER SUM CALCULATION
QYR = Right(Cells(k, i).Value, 4)
If QYR = sysYr Then
fSumYr1 = fSumYr1 + Cells(j, i).Value
Else
fSumYr2 = fSumYr2 + Cells(j, i).Value
End If
End If
i = i + 1
Wend
Cells(j, colEnd).Value = fSumYr1
Cells(j, colEnd + 1).Value = fSumYr2
j = j + 1
Wend









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
replacing value in formula from outside worksheet? Mike[_4_] Excel Discussion (Misc queries) 4 March 24th 08 10:17 PM
help on replacing this formula Abbey Normal Excel Discussion (Misc queries) 6 August 23rd 07 05:17 PM
Replacing half a formula dpal Excel Discussion (Misc queries) 4 February 24th 07 08:43 PM
replacing varaibles in formula monika Excel Programming 1 February 26th 04 01:59 PM
Replacing a value from a formula Squid[_2_] Excel Programming 1 February 14th 04 02:02 PM


All times are GMT +1. The time now is 12:05 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"