Ask Experts Questions for FREE Help !
Ask
    jmcgranahan's Avatar
    jmcgranahan Posts: 1, Reputation: 1
    New Member
     
    #1

    Feb 28, 2008, 02:58 PM
    VBA 6.3 in Excel 2003 - "For" subroutine
    This seems so elementary that I'm afraid to ask, but I need to get this done and I haven't been able to get it to work. I have a pretty basic code that I have been working with and basically what I am looking for is anything in a particular column in my Excel spreadsheet that has the word "Overdue" in it, I want it to calculate the sum paid for that overdue and put it in cell I1 (9th column, 1st row). The word "Overdue" is found in column I in our spreadsheet (which is the 9th column). The paid amount is found in column Q (the 17th column). I created this below and I'm not sure what I am doing wrong. I have originally had the o variable set as currency. Then I have tried it as integer, and neither one does anything. It seems like it should work. Any ideas for this elementary question?
    ------------------------
    Sub Macro2()
    '
    ' Macro2 Macro
    ' Macro recorded 2/28/2008 by jmcgranahan
    '
    ' Keyboard Shortcut: Ctrl+q
    '
    Dim o As Integer
    Dim r As Long
    For r = 1 To 2000
    If Cells(r, 9).Value = "Overdue" Then
    o = o + (Cells(r, 17))
    Exit For
    End If
    Next
    If r = 2001 Then Cells(1, 9) = o
    End Sub


    Jamen McGranahan
    kabia's Avatar
    kabia Posts: 9, Reputation: 2
    New Member
     
    #2

    Feb 29, 2008, 04:44 PM
    I don't use VBA but I do use VB6
    and this is how I would do it

    Dim o As Integer
    Dim r As Long
    For r = 1 To 2000
    If lcase(trim(Cells(r, 9).text)) = lcase(trim("Overdue")) Then
    o = o + (Cells(r, 17)).value
    End If
    Next r
    Cells(1, 9) = o
    End Sub
    melondotnet's Avatar
    melondotnet Posts: 23, Reputation: 1
    New Member
     
    #3

    Mar 13, 2008, 03:04 PM
    Hi, I can program in VBA...

    Try replacing cells, with range.

    To get the value, you use .text, but to write to a cell, use .FormulaR1C1

    Note: R1C1 relate to a number-by-number referance, R = Row, C = Column

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Intertherm Electric Furnace Blower works in "on" not in "auto" [ 6 Answers ]

I have an Intertherm Electric Furnace E2EB-015AH. I came home from work last night, turned the heat on and it didn't work as advertised. I could hear the relays clicking occasionally so I investigated a little and found the elements are heating up and cycling, the relay inside the thermostat cycles...

Excel: How to NOT have email addresses "auto link" [ 1 Answers ]

When I enter an email address in a cell, it becomes a mailto link. How can I turn this off? (I want to leave it on for entered url's though) Thanks!

Excel: CONCATENATE(B2,"-",B3,"-",B4) [ 4 Answers ]

Hi, I would like to concatenate three rows: (Row2, Row3, Row4) of Col A to Row1 of Col B below. I did CONCATENATE(B2,"-",B3,"-",B4), the result was 39065-Thurs-1pm ET. I want the result to become: 11/20/2006-Thurs-1pm ET. Please help. Thanks Column A Column B...

Excel line chart with "confidence band" [ 0 Answers ]

Hello, I am new to this forum and need help with a line chart in Excel. I have 40 years of annual data, each expressed as a mean with a confidence interval (CI) having an upper limit (UL) and a lower limit (LL). Instead of plotting the data using error bars to show the CI, I wanted to plot 3...


View more questions Search