Is it possible to run the code below and also copy the value only form B1 to A2 in sheet…
- User
Is it possible to run the code below and also copy the value only form B1 to A2 in sheet 'Job Request'
If Target.Address = "3" Then Sheets("Job Request").Activate End If
- Assistant
Yes, it is possible to run the code and copy the value from B1 to A2 in the sheet 'Job Request' if the Target address is "3". However, the code you provided does not include the copy functionality. Here is an example code that achieves this:
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$3" Then Sheets("Job Request").Range("A2").Value = Sheets("Job Request").Range("B1").Value End If End SubThis code should be placed in the code module of the worksheet where the change event should be triggered.
- User
Can you please show me the VBA code that will do this
- Assistant
Certainly! Here is the VBA code that will copy the value from B1 to A2 in the sheet 'Job Request' when the value in B3 is changed:
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$3" Then Sheets("Job Request").Range("A2").Value = Sheets("Job Request").Range("B1").Value End If End SubTo add this code to your workbook, follow these steps:
- Press
Alt + F11to open the VBA Editor. - In the Project Explorer window, find the worksheet where you want the code to be executed (e.g., Sheet1).
- Double-click on the worksheet name to open the code window for that worksheet.
- Copy and paste the above code into the code window on the right side.
- Close the VBA Editor.
- Make a change in B3, and the value from B1 will be copied to A2 in the "Job Request" sheet.
- Press
- User
What I want i s different from your solution. This is what I require. The A2 value of my active sheet is copied to B1 in sheet 'Job Request'
- Assistant
Apologies for the misunderstanding. Here is the updated code to copy the value from A2 of the active sheet to B1 in the "Job Request" sheet:
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$2" Then Sheets("Job Request").Range("B1").Value = ActiveSheet.Range("A2").Value End If End SubTo add this code to your workbook, follow the same steps as mentioned before. Now, if you make a change in A2 of the active sheet, the value will be copied to B1 in the "Job Request" sheet.