Find a cell and replace contents

trogtrog

New Member
Joined
Sep 5, 2019
Messages
2
I'm a little out of my depth with a task I'm trying to do in Excel and would appreciate help!

What I'm trying to do, when on sheet A, is create a macro to find a cell on another sheet and replace it's contents with the contents of a cell on sheet A.

For example, on sheet A

Cell A1 has the name which corresponds to one other the other sheets...let's say that the name is 'Biology' which corresponds to a sheet in the same workbook called 'Biology'
Cell A2 has a unique number which will be found somewhere in column A of the other sheet...let's say the number is 310008 which will be found on Row 12, i.e. in cell A12 of sheet Biology
Cell A3 has a manually entered value which, when the macro is triggered (button press), I'd like to find the approriate cell, which will be in the same row as the looked-up value, in column E, and 'paste' the contents of sheet A, Cell A3 into the looked-up cell, which in this example is sheet Biology, cell E12.

Can anyone help please?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi and welcome to teh forum!

Put the following code in the events of your sheet

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address(0, 0) = "[COLOR=#ff0000]A3[/COLOR]" Then
    Dim sh As Worksheet, f As Range, sh1 As Worksheet
    If Target.Count > 1 Then Exit Sub
    If Range("[COLOR=#ff0000]A1[/COLOR]").Value = "" Or Range("[COLOR=#ff0000]A2[/COLOR]").Value = "" Then Exit Sub
    For Each sh In Sheets
      If LCase(sh.Name) = LCase(Range("[COLOR=#ff0000]A1[/COLOR]").Value) Then
        Set sh1 = sh
        Exit For
      End If
    Next
    If Not sh1 Is Nothing Then
      Set f = Sheets(Range("[COLOR=#ff0000]A1[/COLOR]").Value).Range("[COLOR=#ff0000]A:A[/COLOR]").Find(Range("[COLOR=#ff0000]A2[/COLOR]").Value, , xlValues, xlWhole)
      If Not f Is Nothing Then
        f.Offset[COLOR=#ff0000](, 4)[/COLOR].Value = Target.Value
        MsgBox "Updated Value"
      Else
        MsgBox "The value does not exist"
      End If
    Else
      MsgBox "The sheet does not exist"
    End If
  End If
End Sub
-----------------------------------
SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.

-----------------------------------

Go back to the sheet and type something in cell A3, the other sheet will be updated automatically.
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top