Search code examples
excelvbacellworksheet

How to change value of cell in a different sheet


I'm trying to replace the value of a cell in the "Visualizer" sheet with the value of a cell in the "Automater" worksheet. However, nothing happens.

This is my code:

Sub RepForm_Click()
    Dim visualizer3 As Worksheet, automater As Worksheet

    Set visualizer3 = Sheets("Visualizer")
    Set automater = Sheets("Automater")
    Range("C22").Value = Range("D24").Value <-- Replaces a cell in the same sheet, works perfectly
    visualizer3.Range("E2").Value = Range("D24").Value <-- Replaces a cell in a different sheet, doesn't work
End Sub

Solution

  • You need to qualify your ranges... you didn't specify automater.range().

    Sub RepForm_Click()
        Dim visualizer3 As Worksheet, automater As Worksheet
        Set visualizer3 = Sheets("Visualizer")
        Set automater = Sheets("Automater")
        visualizer3.Range("E2").Value = automater.Range("D24").Value
    End Sub
    

    Edit1: Updated cell reference on visualizer3 from C22 to E2.