mardi 23 août 2016

VBA Macro Excell if then loop check value

please help, i am trying to get the below code to work and not sure if i am completely wrong on this. i have tried more complex ones but not winning either way, this one seems the most simple to me but it doesnt do anything, just types "credit" next to whatever cell is highlighted currently.

Sub Cmplt()

Dim rngTest As Range
Dim aCell As Range


Set rngTest = ThisWorkbook.Worksheets("Differences").Range("E3:E30")

For Each aCell In rngTest

If aCell.Value < 0 Then ActiveCell.Offset(0, 1) = "Debit"

If aCell.Value > 0 Then ActiveCell.Offset(0, 1) = "Credit"

Next aCell

End Sub

I need the macro to go through the range and if the value in the range is negative, write "debit" in the cell next to it and write credit for positive numbers.

much appreciated. thank you

Aucun commentaire:

Enregistrer un commentaire