Click on a cell to copy&paste the cell value into the next empty row.

Ironhan

New Member
Joined
Jul 22, 2020
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

Got two questions, hope you guys could help me out.

Q 1.

I got a range of cells [A1:C20] and I would like for any cell I click on in the range [A1:C20], to be copied and pasted in the empty cell of the range [D5:D20].
Eg. Click on cell[A1], the value gets copy&paste in [D5]. Click on cell[B13], the value gets copy&paste in [D6] and so on.

Q 2.

Similar to the one above, but if I click a specific cell(let's say it's [F1]) the whole range [D5:D20] gets emptied. (or the blank value gets copied and pasted, doesn't really matter)

Not sure if it'd help, but below is somewhat like what I'm trying to achieve except it only copies&pastes the value into one specific cell.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Count = 1 And Target.Column = 4 Then
    Sheets("Sheet1").Range("F1").Value = Target.Value
End If

End Sub



Hopefully, this is an easy one, and appreciate your help!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("A1:C20")) Is Nothing Then
      Target.Copy Range("D" & Rows.Count).End(xlUp).Offset(1)
   ElseIf Target.Address(0, 0) = "F1" Then
      Range("D5:D20").Clear
   End If
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("A1:C20")) Is Nothing Then
      Target.Copy Range("D" & Rows.Count).End(xlUp).Offset(1)
   ElseIf Target.Address(0, 0) = "F1" Then
      Range("D5:D20").Clear
   End If
End Sub

Hi,

This works perfectly but the value starts to get pasted from D2.
Any ways to make it starts from D5?

Thank you so much for your help.
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("A1:C20")) Is Nothing Then
      On Error GoTo Oops
      Target.Copy Range("D5:D20").SpecialCells(xlBlanks)(1)
      On Error GoTo 0
   ElseIf Target.Address(0, 0) = "F1" Then
      Range("D5:D20").Clear
   End If
   Exit Sub
Oops:
   MsgBox "No space available in D5:D20"
End Sub
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("A1:C20")) Is Nothing Then
      On Error GoTo Oops
      Target.Copy Range("D5:D20").SpecialCells(xlBlanks)(1)
      On Error GoTo 0
   ElseIf Target.Address(0, 0) = "F1" Then
      Range("D5:D20").Clear
   End If
   Exit Sub
Oops:
   MsgBox "No space available in D5:D20"
End Sub

This is perfect, much appreciated :)

Thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
This is perfect, much appreciated :)

Thanks!

Hi again, is there a way to fill the cleared cell with a specific color?

VBA Code:
ElseIf Target.Address(0, 0) = "F1" Then
      Range("D5:D20").Clear

This clears the range and leaves it in blank white cells, wondering if I could make it fill them with the original color.

Thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
Hi again, is there a way to fill the cleared cell with a specific color?

VBA Code:
ElseIf Target.Address(0, 0) = "F1" Then
      Range("D5:D20").Clear

This clears the range and leaves it in blank white cells, wondering if I could make it fill them with the original color.

Thanks!
 
Upvote 0
Just change Clear to clearcontents
 
Upvote 0
Just change Clear to clearcontents

Thanks again Fluff,

I was wondering if you could help me troubleshooting this worksheet.

I've managed to apply the code you gave me, but when I try to protect the worksheet, it doesn't copy&paste the cell value on click.

This is after I tried with allowing select and edit the locked/unlocked cells. (Basically protecting the sheet in any form will cause the error)

Would there be any ways to get around this? Below is the link to the said worksheet for your reference.


Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,324
Messages
6,118,890
Members
448,854
Latest member
Eduard_Stoo

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