Paul,
Thanks for the help as usual. It's the one I expected.

dguillett,
Thank you for the solution and advice. I'm not very good in VB, therefore
my programme may inefficient. However I will learn the find method too.
Thank you very much.

Regards,
Dilan



On Thu, Aug 30, 2012 at 6:12 PM, Paul Schreiner <schreiner_p...@att.net>wrote:

> It IS less efficient,
> but if you wanted to fix it...
> You're formula is NOT "=sum(G1:G&r)"
> but instead
> "=sum(G1:G" & r & ")"
>
>
>
> (because you want a string of characters, the VALUE of a variable, then
> another string of characters.)
>
>
>
> *Paul*
>
> -----------------------------------------
> *“Do all the good you can,
> By all the means you can,
> In all the ways you can,
> In all the places you can,
> At all the times you can,
> To all the people you can,
> As long as ever you can.” - John Wesley
> *-----------------------------------------
>
>
>  ------------------------------
> *From:* dguillett1 <dguille...@gmail.com>
> *To:* excel-macros@googlegroups.com
> *Sent:* Thu, August 30, 2012 10:17:10 AM
>
> *Subject:* Re: $$Excel-Macros$$ Macro to Calculate a total upon a
> condition
>
>  Your method of looping is inefficient when compared to FIND.
>
> Don Guillett
> Microsoft Excel Developer
> SalesAid Software
> dguille...@gmail.com
>
>  *From:* Dilan De Silva <dila...@gmail.com>
> *Sent:* Thursday, August 30, 2012 8:58 AM
> *To:* excel-macros@googlegroups.com
> *Subject:* Re: $$Excel-Macros$$ Macro to Calculate a total upon a
> condition
>
>  Dear  Guillett,
> Thank for the solution. Your answer is perfect.
> I wrote below macro for the same project. However it's not working
> properly. I tried to put the sum formula to get the total. I think error is
> writing the upper cell reference(e.g:G50).
> Do you have any idea about getting the correct cell reference for my
> method.Please note that I'm concerning the answer you mentioned as"WRONG",
> it means I need the double of the correct total.
> -------------------
>  Private Sub total()
> For r = 1 To 10000
> If Cells(r, "C") = "COLLECTION" Then
> Cells(r, "G") = "=sum(G1:G&r)"
> ' For an example if r=50 then Cells(50,"G")=Sum(G50:G1)
> End If
> Next
> End Sub
> ---------------------
>
> Regards,
> Dilan
>
>
> On Thu, Aug 30, 2012 at 4:31 PM, dguillett1 <dguille...@gmail.com> wrote:
>
>>   See attached using this macro for the CORRECT answer
>>
>> Option Explicit
>> Sub sumcollectionSAS()
>> Dim mf As Range
>> Dim cr As Long
>> Dim c As Range
>> Dim ms As Long
>> Dim firstaddress As String
>> Set mf = Columns("C").Find(What:="collection", LookIn:=xlValues, _
>>         LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
>> If Not mf Is Nothing Then cr = mf.Row
>> 'MsgBox cr
>> With Columns("d:f")
>>     Set c = .Find(What:="collection", LookIn:=xlValues, _
>>         LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
>>         MatchCase:=False, SearchFormat:=False)
>>
>>     If Not c Is Nothing Then
>>         firstaddress = c.Address
>>         Do
>>         'MsgBox c.Row
>>             ms = ms + Cells(c.Row, "g")
>>             Set c = .FindNext(c)
>>         Loop While Not c Is Nothing And c.Address <> firstaddress
>>     End If
>> End With
>>
>> 'MsgBox ms
>> Cells(cr, "g") = ms
>> End Sub
>>
>> Don Guillett
>> Microsoft Excel Developer
>> SalesAid Software
>> dguille...@gmail.com
>>
>>  *From:* Dilan De Silva <dila...@gmail.com>
>> *Sent:* Thursday, August 30, 2012 3:18 AM
>> *To:* excel-macros@googlegroups.com
>> *Subject:* $$Excel-Macros$$ Macro to Calculate a total upon a condition
>>
>>   Dear friends,
>> I want to programme a macro to calculate a total.
>> Refer *both sheets* of attached Excel sheet.
>> When the macro runs, it should search the word "COLLECTION".
>> After the macro found the word; the cell  on Coloumn G of same row(In
>> this sheet cell G122) shoud have a formula to find total of all cells value
>> in column G from row 1 to a raw before the "COLLECTION"word located.
>>
>> Regards,
>> Dilan
>> --
>> Join official facebook page of this forum @
>> https://www.facebook.com/discussexcel
>>
>> FORUM RULES (1120+ members already BANNED for violation)
>>
>> 1) Use concise, accurate thread titles. Poor thread titles, like Please
>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
>> will not get quick attention or may not be answered.
>>
>> 2) Don't post a question in the thread of another member.
>>
>> 3) Don't post questions regarding breaking or bypassing any security
>> measure.
>>
>> 4) Acknowledge the responses you receive, good or bad.
>>
>> 5) Cross-promotion of, or links to, forums competitive to this forum in
>> signatures are prohibited.
>>
>> 6) Jobs posting is not allowed.
>>
>> 7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
>>
>> NOTE : Don't ever post personal or confidential data in a workbook. Forum
>> owners and members are not responsible for any loss.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "MS EXCEL AND VBA MACROS" group.
>> To post to this group, send email to excel-macros@googlegroups.com.
>> To unsubscribe from this group, send email to
>> excel-macros+unsubscr...@googlegroups.com.
>>
>>
>>  --
>> Join official facebook page of this forum @
>> https://www.facebook.com/discussexcel
>>
>> FORUM RULES (1120+ members already BANNED for violation)
>>
>> 1) Use concise, accurate thread titles. Poor thread titles, like Please
>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
>> will not get quick attention or may not be answered.
>>
>> 2) Don't post a question in the thread of another member.
>>
>> 3) Don't post questions regarding breaking or bypassing any security
>> measure.
>>
>> 4) Acknowledge the responses you receive, good or bad.
>>
>> 5) Cross-promotion of, or links to, forums competitive to this forum in
>> signatures are prohibited.
>>
>> 6) Jobs posting is not allowed.
>>
>> 7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
>>
>> NOTE : Don't ever post personal or confidential data in a workbook. Forum
>> owners and members are not responsible for any loss.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "MS EXCEL AND VBA MACROS" group.
>> To post to this group, send email to excel-macros@googlegroups.com.
>> To unsubscribe from this group, send email to
>> excel-macros+unsubscr...@googlegroups.com.
>>
>>
>>
>
> --
> Join official facebook page of this forum @
> https://www.facebook.com/discussexcel
>
> FORUM RULES (1120+ members already BANNED for violation)
>
> 1) Use concise, accurate thread titles. Poor thread titles, like Please
> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
> will not get quick attention or may not be answered.
>
> 2) Don't post a question in the thread of another member.
>
> 3) Don't post questions regarding breaking or bypassing any security
> measure.
>
> 4) Acknowledge the responses you receive, good or bad.
>
> 5) Cross-promotion of, or links to, forums competitive to this forum in
> signatures are prohibited.
>
> 6) Jobs posting is not allowed.
>
> 7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
>
> NOTE : Don't ever post personal or confidential data in a workbook. Forum
> owners and members are not responsible for any loss.
> ---
> You received this message because you are subscribed to the Google Groups
> "MS EXCEL AND VBA MACROS" group.
> To post to this group, send email to excel-macros@googlegroups.com.
> To unsubscribe from this group, send email to
> excel-macros+unsubscr...@googlegroups.com.
>
>
>
> --
> Join official facebook page of this forum @
> https://www.facebook.com/discussexcel
>
> FORUM RULES (1120+ members already BANNED for violation)
>
> 1) Use concise, accurate thread titles. Poor thread titles, like Please
> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
> will not get quick attention or may not be answered.
>
> 2) Don't post a question in the thread of another member.
>
> 3) Don't post questions regarding breaking or bypassing any security
> measure.
>
> 4) Acknowledge the responses you receive, good or bad.
>
> 5) Cross-promotion of, or links to, forums competitive to this forum in
> signatures are prohibited.
>
> 6) Jobs posting is not allowed.
>
> 7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
>
> NOTE : Don't ever post personal or confidential data in a workbook. Forum
> owners and members are not responsible for any loss.
> ---
> You received this message because you are subscribed to the Google Groups
> "MS EXCEL AND VBA MACROS" group.
> To post to this group, send email to excel-macros@googlegroups.com.
> To unsubscribe from this group, send email to
> excel-macros+unsubscr...@googlegroups.com.
>
>
>
> --
> Join official facebook page of this forum @
> https://www.facebook.com/discussexcel
>
> FORUM RULES (1120+ members already BANNED for violation)
>
> 1) Use concise, accurate thread titles. Poor thread titles, like Please
> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
> will not get quick attention or may not be answered.
>
> 2) Don't post a question in the thread of another member.
>
> 3) Don't post questions regarding breaking or bypassing any security
> measure.
>
> 4) Acknowledge the responses you receive, good or bad.
>
> 5) Cross-promotion of, or links to, forums competitive to this forum in
> signatures are prohibited.
>
> 6) Jobs posting is not allowed.
>
> 7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
>
> NOTE : Don't ever post personal or confidential data in a workbook. Forum
> owners and members are not responsible for any loss.
> ---
> You received this message because you are subscribed to the Google Groups
> "MS EXCEL AND VBA MACROS" group.
> To post to this group, send email to excel-macros@googlegroups.com.
> To unsubscribe from this group, send email to
> excel-macros+unsubscr...@googlegroups.com.
>
>
>

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.


Reply via email to