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

Ironhan

New Member
Joined
Jul 22, 2020
Messages
8
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,468
Office Version
  1. 365
Platform
  1. Windows
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
 

Ironhan

New Member
Joined
Jul 22, 2020
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,468
Office Version
  1. 365
Platform
  1. Windows
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
 

Ironhan

New Member
Joined
Jul 22, 2020
Messages
8
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,468
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Ironhan

New Member
Joined
Jul 22, 2020
Messages
8
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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!
 

Ironhan

New Member
Joined
Jul 22, 2020
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
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!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,468
Office Version
  1. 365
Platform
  1. Windows
Just change Clear to clearcontents
 

Ironhan

New Member
Joined
Jul 22, 2020
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,129,390
Messages
5,636,035
Members
416,892
Latest member
Bensch

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
Top