Setting Excel cell value based on another cell value using VBA
I have the following spreadsheet. When ever there is an x in cell B I need to populate the d and e cells in the same row using an equation I have. if there is no x in the b cell I need to manually enter values into cells d & e.
How do I make my code non-row specific?
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim val As String val = Range("B3").Value If val = "x" Then Range("E3").Value = Range("d2").Value * Range("G2").Value Range("D3").Value = Range("D2").Value End If End Sub
I'm not sure if I understand correctly, but if you have a parameter: row = 3 you can use Range("E" & row) instead of Range("E3").
Put a loop around that where you vary 'row' for the rows you want to modify.
Hope that helps!