Solved

EASY ?: How to get the previous row value in a Range?  Range.Previous??

Posted on 2004-08-11
5
178 Views
Last Modified: 2011-09-20
How do i get the previous row in a range?  i need pname to equal the previous row's value so i can check it against sTrader.    

   j = 1
    With Worksheets("study").Range("C36:C234")
        For Each i In .Cells
            sTrader = takeCaptionAfter(CStr(i.value), 2)
            pName = Cells(Selection.Row + 1, Selection.Column).value
           
            If InStr(sTrader, "MEMBER_CAPTION") > 0 Then
                tmpStr = sTrader
            Else
                If CStr(sTrader) <> CStr(pName) Then
                    newTrader = True
                    Arow = 3 + j
                End If
                Worksheets("report").Range("A" & j + 3).value = sTrader
                j = j + 1
            End If
           
        Next
0
Comment
Question by:efarhat
  • 3
  • 2
5 Comments
 

Author Comment

by:efarhat
ID: 11775971
i changed:
pName = Cells(i.Row - 1, i.Column).value

still doesn't work.
0
 
LVL 35

Accepted Solution

by:
mvidas earned 25 total points
ID: 11776003
Hi efarhat,

If you're trying to get the value of the cell above each "i" then

pName = i.Offset(-1,0).Value    

should do it.
Matt
0
 

Author Comment

by:efarhat
ID: 11776279
this works: Cells(i.Row - 1, i.Column).value
0
 

Author Comment

by:efarhat
ID: 11776283
i'll give you the pts anyway, since i can't give them to myself.
0
 
LVL 35

Expert Comment

by:mvidas
ID: 11776381
Thanks, though you could have had it closed/refunded. With i being a cell (as defined by your for loop), it works the same as mine anyways (just longer)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question