Copy & Paste Cell value into another sheet based on selection not fixed range - Macro/vba.

msussams

New Member
Joined
Mar 28, 2021
Messages
3
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi All,
I am having an issue with my VBA/Macro
I'm trying to copy 5 cell contents to a different sheet
I've managed to input data to a fixed cell range and it'll insert it at the bottom of data
but I need to do it based on selected cells.

1616922381756.png

so basically 09:15;J Jack Bob; H23456; DUU and YY should be copied and pasted into this:
1616922451197.png



VBA Code:
Sub CopyName()
Worksheets("JohnSmith").Range("A" & Rows.Count).End(xlUp).Offset(0, 0) = Worksheets("Diary").Range(ActiveCell.Offset(0, -1)).Value   'date
Worksheets("JohnSmith").Range("B" & Rows.Count).End(xlUp).Offset(1, 1) = Worksheets("Diary").Range(ActiveCell.Offset(0, 0)).Value   'name
Worksheets("JohnSmith").Range("C" & Rows.Count).End(xlUp).Offset(1, 1) = Worksheets("Diary").Range(ActiveCell.Offset(1, 0)).Value
Worksheets("JohnSmith").Range("D" & Rows.Count).End(xlUp).Offset(1, 1) = Worksheets("Diary").Range(ActiveCell.Offset(2, 0)).Value
Worksheets("JohnSmith").Range("E" & Rows.Count).End(xlUp).Offset(1, 1) = Worksheets("Diary").Range(ActiveCell.Offset(3, 0)).Value
Call selectandformat
End Sub

This is what i'm trying to do - but it doesn't work
Does anyone have any tips/pointers to show where i am going wrong?

Many thanks in advance
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Osvaldo Palmeiro

Well-known Member
Joined
Feb 24, 2009
Messages
635
Office Version
  1. 365
Platform
  1. Windows
... input data to a fixed cell range
I've considered this range as C2:C5 of sheet Diary.

Please, see if the code below could be a start point.
VBA Code:
Sub CopyName()
  Sheets("Diary").[C2:C5].Copy
  Sheets("JohnSmith").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues, Transpose:=True
  Sheets("JohnSmith").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = Date + Sheets("Diary").[B2]
'Call selectandformat
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,380
Messages
5,635,919
Members
416,887
Latest member
SheriE

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