I am currently working on an excel application where I have a macro, operated by a button click, which resets the numerical values within certain cells in a table.
Within this table there are 3 columns; "Quantity Fitted (n)", "Quantity Required (m)" and "Lock Configuration".
What I need to happen, is when the button is clicked, the numerical values for each line within the "Quantity Fitted (n)" column are reset to match the values displayed within the "Quantity Required (m)" column of the same line.
However, if the cell value within the "Lock Configuration" column of that row is set to "locked", I want the "Quantity Fitted (n)" value to remain unchanged after the button click.
I hope this makes sense! Here's my current attempt to code this:
Public Sub Reset_Quantity_Fitted()
'Macro to make quantity fitted equal to quantity required
    Dim rng As Range
    Dim cell As Range
    Set rng = Worksheets(ActiveSheet.Name).ListObjects("Table_" & ActiveSheet.Name).ListColumns("Quantity Fitted (n)").DataBodyRange
For Each cell In rng.Cells
    If rng.Offset(, 5) = "Locked" Then
        cell = Worksheets(ActiveSheet.Name).ListObjects("Table_" & ActiveSheet.Name).ListColumns("Quantity Fitted (n)").DataBodyRange
    Else
        cell = Worksheets(ActiveSheet.Name).ListObjects("Table_" & ActiveSheet.Name).ListColumns("Quantity Required (m)").DataBodyRange
    End If
Next cell
End Sub
This approach was recommended by another user on this site, however hen running this code I get the following error:
Run-time error '13': Type mismatch
Can anyone help me identify what is wrong with this code?
 
     
    