Copy data into new rows in a table and change the year of copied data

Ramonde

New Member
Joined
Nov 25, 2015
Messages
1
Goodday

Post on your forum are very helpful - today I needs some help with something that I cant find on the web.

I need to copy data in a table and add it as new rows in the same table. I then need to change the year date to a new date for eg. from 2019 tot 2020. (So in the end I have to ranges the original 2019 range and the new range 2020)
I found the macro to copy and add the data in the table posted on the website www.contextures.com. It does exactly what I want to do (the macro is below). I now need to change the year to the next year. Mostly it will be just say from 2019 to 2020 and the next time it will be from 2020 to 2021 depending on the year I am working with. Or it must be based on a cell value (that will be maybe better because one can skip a year if needed for eg going from 2019 tot 2021)

It there is not a lot of data in in the table it is easy to use find and replace but once the data gets more its going to be difficult and one is going to get confused with the year ranges.

I attached a sample range and hope someone can help me to complete the macro with the find and replace. I will need to use the same function on different tables in the workbook.

Thanks for the help.

Regards
Ramonde


Copy data.xlsm
ABCD
3YearCary overOwn / RentedFarm Name
42019JaEieHarmonie
52019JaEieMizpah
62019JaEieMybou
72019JaEieBlackwood
82019JaEieVanstadensdrif
92019JaEieSG/KV
102019JaEieParadyskloof
112019JaEieRooderand
Sheet1
Cells with Data Validation
CellAllowCriteria
B4:B11List=Ja



Sub CopySelectionVisibleRowsEnd()
Dim ws As Worksheet
Dim mySel As Range
Dim lRow As Long
Dim lRowNew As Long
Dim lRowsAdd As Long
Dim myList As ListObject
Dim myListRows As Long
Dim myListCols As Long

Set ws = ActiveSheet
Set mySel = Selection.EntireRow
Set myList = ActiveCell.ListObject
myListRows = myList.Range.Rows.Count
myListCols = myList.Range.Columns.Count
lRow = ws.Cells.Find(What:="*", _
SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, _
LookIn:=xlValues).Row + 1

mySel.SpecialCells(xlCellTypeVisible).Copy
ws.Cells(lRow, 1).PasteSpecial Paste:=xlPasteAll

lRowNew = ws.Cells.Find(What:="*", _
SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, _
LookIn:=xlValues).Row + 1
lRowsAdd = lRowNew - lRow

With myList
.Resize ws.Range(.Range.Resize(myListRows + lRowsAdd, myListCols).Address)

End With



Application.CutCopyMode = False

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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