Copy Data to Running List on Another Worksheet - Need to add sheet name from selected Range

bbalch

Board Regular
Joined
Feb 23, 2015
Messages
61
Hello everyone,

I have some vba I use on a workbook with multiple tabs. The code copies a selected range from a tab (the range will be a single row - columns A - H) each time it's selected and pastes the selected range to the next available row on the sheet named "List".

2 Questions:
1) I would like to add the sheet name in column I on the "List" sheet to document where the data came from. For example, if data from the sheet "00-100" Range("A10:H10") is copied to the "List" sheet and pasted to Range("A5:H5") I would like to add "00-100" in Cell I5. See the attached image - with the green cell as the desired outcome.
- Any suggestions on how to do this?
2) Is there a better way to do this than the code below? This code seems to be a little slow for a copying and pasting a range of 8 cells.


VBA Code:
Dim myRange As Range
Set myRange = Selection

Dim Lr As Long
  Lr = Worksheets("List").Range("A" & Rows.Count).End(xlUp).Row
  ' Lr = Worksheets("List").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row


myRange.Copy

Worksheets("List").Range("A" & Lr + 1).PasteSpecial Paste:=xlPasteAllExceptBorders
 

Attachments

  • 2021-02-26_14-46-41.png
    2021-02-26_14-46-41.png
    42.8 KB · Views: 9

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Would this work for you?

VBA Code:
Sub Sheetname()

Dim myRange As Range
Set myRange = Selection

Dim Lr As Long
  Lr = Worksheets("List").Range("A" & Rows.Count).End(xlUp).Row
  ' Lr = Worksheets("List").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row

myRange.Copy

Worksheets("List").Range("A" & Lr + 1).PasteSpecial Paste:=xlPasteAllExceptBorders
Worksheets("List").Range("I" & Lr + 1).Value = myRange.Parent.Name

End Sub
 
Upvote 0
Solution
myRange.Copy Worksheets("List").Range("A" & Lr + 1)
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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