Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Full Range of Cells inside a Loop

Status
Not open for further replies.

whitebearstech

IS-IT--Management
May 16, 2011
2
US
Hi,

I'm new to VBA and was trying really really hard not to ask questions, but I'm stumped on a simple code. I just want the code to see if row B has a value of CR. If so, make rows d and e negative. The following code works for only 1-10, but I need it to go through every row that has a value from column A.

This needs to be in the code "Cells(Rows.Count, "A").End(xlUp).Row" but I keep getting a ton of errors every time a try.


For Temp = 1 To 10
If Range("B" & Temp).Value = "CR" Then
Range("D" & Temp) = Abs(Range("D" & Temp).Value) * -1
Range("E" & Temp) = Abs(Range("E" & Temp).Value) * -1
End If
Next Temp
 
hi,
Code:
    Dim r As Range
    
    With ActiveSheet
        For Each r In .Range(.Cells(1, "A"), .Cells(.Rows.Count, "A").End(xlUp))
            If .Cells(r.Row, "B").Value = "CR" Then
                nVal = .Cells(r.Row, "D").Value
                With .Cells(r.Row, "D")
                    .Value = Abs(.Value) * -1
                End With
                With .Cells(r.Row, "E")
                    .Value = Abs(.Value) * -1
                End With
            End If
        Next
    End With


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top