Populate a Cell with another cell's value in a single click

Viewed 126

I'm new with VB coding in Excel and would like to know how if I can click on a particular cell and have that cell loaded with the value of another cell with a single click. For example, if the value “SVE” is in cell AP1, how can I click on the blank cell B8 and have “SVE” loaded into B8 in a single click without typing the value “SVE” prior to clicking on the cell? Does it require a formula or does it have to be done with VBA code?

1 Answers

Populate Cell on Single Click

  • You need VBA to do this. Select Developer > Visual Basic to open the Visual Basic Editor. Open View > Project Explorer. Double-click on your project (VBAProject(YourWorkbookName.xlsm)) and double-click the worksheet (e.g. Sheet1(Data)) where you need the requirement. Into the newly opened sheet module window, copy/paste the following code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Range("B8"), Target) Is Nothing Then Exit Sub
    Target.Value = Range("AP1").Value
End Sub
  • It will actually only work when you select the cell i.e. the cell isn't selected and you click on it.
Related