PDA

View Full Version : Simple excel macro if then condition to manipulate column values



tnertster
04-17-2016, 05:03 PM
Hi all! Thanks for the help! Been years since i have done any VBA in fact about all I can recall is use ' for comments - so need some help w simple problem in excel.
Straight to it:
>>>>>>>>>>>>>
'need an excel macro that checks each value in a column and changes the
'value in another column based on a condition....


'For rows 6 thru 4000:
'Check the value in column N row r# ( r# being the number of the row currently being evaluated)
'and if column N row r# is empty then the value of column G row r# remains unchanged
'else set value Gr# = "USED"


Dim score As Integer, result As String
score = Range("G$").Value


If score Then 'If value in column N row n is not nil then column G row n = "USED"
result = "pass"
Else
result = "fail" 'value in column G row n remains unchanged
End If


Range("B1").Value = result
>>>>>>>>>>>>
Thanks again!!!
cheers

Paul_Hossler
04-17-2016, 05:54 PM
Some requirements I could figure out or guess at, but the second half is very confusing

More details and I'll try again



Option Explicit
'need an excel macro that checks each value in a column and changes the
'value in another column based on a condition....
Sub Rusty()
Dim iRow As Long
Dim score As Integer, result As String

'For rows 6 thru 4000:
For iRow = 6 To 4000

'Check the value in column N row r# and if column N row r# is empty
If Len(ActiveSheet.Cells(iRow, 14).Value) = 0 Then
'then the value of column G row r# remains unchanged

'else set value Gr# = "USED"
Else
ActiveSheet.Cells(iRow, 7).Value = "USED"
End If

'can't understand the rest
' score = Range("G$").Value
' If score Then 'If value in column N row n is not nil then column G row n = "USED"
' result = "pass"
' Else
' result = "fail" 'value in column G row n remains unchanged
' End If
' Range("B1").Value = result

End Sub

tnertster
04-17-2016, 08:58 PM
Thanks Paul! Worked like a charm - huge time saver. :thumb

-