Copy row from one sheet to another based on a cell value

FJPunisher

New Member
Joined
Mar 2, 2021
Messages
8
Office Version
  1. 2019
Platform
  1. Windows
Hello everyone,
My xls has a drop down in B15 (e.g Schools), based on the option selected in this drop down, C15 is updated with a Code (e.x PH_100).
I am trying to update Row B26 on sheet1 with data in sheet27 based on C15 value,
The data is Sheet27 has been assigned name (e.g. PB_200DD = K2:K7)

Below is not working, please help.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = ("$C$15") Then
If Target.Text = "PB_100" Then
Sheets("Sheet27").Range("K2:K7").Copy Destination:=Sheets("Sheet1").Range("B26")

' ElseIf Target.Text = "PB_200" Then
' Sheets("Sheet27").Range(PB_200DD).Copy Destination:=Sheets("Sheet1").Range("B26")

' ElseIf Target.Text = "PB_300" Then

' ElseIf Target.Text = "PB_400" Then

' Else


End If
End If
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I figured it out, but have few new questions now =0)

Where should i past the code so everytime value is $C$15 changes (not clicked/activated), this code runs?
Also everytime value in $C$15 changes, i want to clear previous data from Sheets("User").Range("B26") before pasting new data.

---CODE---
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = ("$C$15") Then
If Target.Text = "PB_100" Then
Sheets("Consumption").Range("PB_100DD").Copy Destination:=Sheets("User").Range("B26")

ElseIf Target.Text = "PB_200" Then
Sheets("Consumption").Range("PB_200DD").Copy Destination:=Sheets("User").Range("B26")

ElseIf Target.Text = "PB_300" Then
Sheets("Consumption").Range("PB_300DD").Copy Destination:=Sheets("User").Range("B26")

ElseIf Target.Text = "PB_400" Then
Sheets("Consumption").Range("PB_400DD").Copy Destination:=Sheets("User").Range("B26")

ElseIf Target.Text = "PB_500" Then
Sheets("Consumption").Range("PB_500DD").Copy Destination:=Sheets("User").Range("B26")

End If
End If
End Sub


Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,470
Messages
6,124,993
Members
449,201
Latest member
Lunzwe73

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