'If row contains any values, multiply two cells

I want column S to multiply the value of column G and column R until the last row of my data set (The length of the data set varies). Does anyone know how to go about this? Currently, I am trying things like:

    Dim LastRow As Long, d As Long
    LastRow = Cells(Rows.Count, "U").End(xlUp).Row
    For d = 2 To LastRow
    If Range("U" & d).Value = "" Then Set rw.Columns("S") = rw.Columns("F").Value * rw.Columns("R").Value * 0.01
    Next d

But they don't work. It does not seem that difficult to me, but I still can't figure it out. I would really appreciate any help!

Raw Data



Solution 1:[1]

Please, try using the next code. You did not answer my clarification question, so it works on the assumption that the column S:S is filled with the multiplication result only for empty cells in column U:U. If not an empty cell, a null string will be filled. If already there are values in S:S, which must be kept, please state that and I will adapt the code to keep them:

Sub FillSSColl()
  Dim sh As Worksheet, lastR As Long, rngS As Range
  
  Set sh = ActiveSheet
  lastR = sh.Range("U" & sh.rows.count).End(xlUp).row

  Set rngS = sh.Range("S2:S" & lastR)
  rngS.value = Application.Evaluate("=If(" & rngS.Offset(0, 2).Address(0, 0) & "= """"," & _
         rngS.Offset(0, -13).Address(0, 0) & " * " & rngS.Offset(0, -1).Address(0, 0) & " * 0.01,"""")")
End Sub

But your question meaning in words does not match your code attempt...

If you want the code to calculate if row contains any value, as the title states, the code should be modified from If(" & rngS.Offset(0, 2).Address(0, 0) & "= """"," in If(" & rngS.Offset(0, 2).Address(0, 0) & "<> """",". I tried following what I could deduce looking to your code.

Edited:

Please, try the version filling all S:S column for the U:U column filled range:

Sub FillSSColl_bis()
  Dim sh As Worksheet, lastR As Long, rngS As Range
  
  Set sh = ActiveSheet
  lastR = sh.Range("U" & sh.rows.count).End(xlUp).row

  Set rngS = sh.Range("S2:S" & lastR)
  rngS.value = Application.Evaluate(rngS.Offset(0, -13).Address(0, 0) & " * " & rngS.Offset(0, -1).Address(0, 0) & " * 0.01")
End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1