#1
|
|||
|
|||
Copy row and change details
Hello
I have created a macro in Excel (using the Record Macro function) that inserts a copy of row 13 and changes some of the details in the copied row (please see code below). Is it possible to amend the code so that it copies a highlighted row instead of always row 13 and changes the details of the new row? Kind regards. Taryn ================================= Sub BankCharges() ' ' BankCharges Macro ' Inserts Bank Charges Script (JNW1) ' ' Keyboard Shortcut: Ctrl+Shift+B ' Rows("13:13").Select Selection.Copy Selection.Insert Shift:=xlDown Rows("14:14").Select Selection.Font.Bold = False Range("H14").Select ActiveCell.FormulaR1C1 = "8920" Range("I14").Select ActiveCell.FormulaR1C1 = "8920" Range("K14").Select ActiveCell.FormulaR1C1 = "NL" Range("O14").Select ActiveCell.FormulaR1C1 = "=0-R[-1]C" Range("O15").Select End Sub |
#2
|
|||
|
|||
.
See if this edit does what you are wanting : Code:
Sub BankCharges() ' ' BankCharges Macro ' Inserts Bank Charges Script (JNW1) ' ' Keyboard Shortcut: Ctrl+Shift+B ' 'Rows("13:13").Select Selection.Copy Selection.Insert Shift:=xlDown Rows("14:14").Select Selection.Font.Bold = False Range("H14").Select ActiveCell.FormulaR1C1 = "8920" Range("I14").Select ActiveCell.FormulaR1C1 = "8920" Range("K14").Select ActiveCell.FormulaR1C1 = "NL" Range("O14").Select ActiveCell.FormulaR1C1 = "=0-R[-1]C" Range("O15").Select End Sub |
#3
|
|||
|
|||
Hi
Thanks for replying. However, can you let me know what you have edited, as the code looks the same to me? Kind regards. Taryn |
#4
|
|||
|
|||
.
This line was commented out : 'Rows("13:13").Select |
#5
|
|||
|
|||
I managed to do it by selecting "use relative references" before recording the macro, which I didn't realise was an option.
Kind regards. Taryn |
#6
|
|||
|
|||
Glad you found an answer. Cheers !
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calendar view showing body or event details - how do you change? | smf1234 | Outlook | 0 | 07-12-2019 01:46 PM |
Project details | rhjones19 | Project | 0 | 08-15-2017 12:59 PM |
change 'Found.EntireRow.Copy' to a # of columns | trevorc | Excel Programming | 2 | 01-08-2017 12:40 AM |
Want to change Macro to copy and paste data to new sheet | Vortex69 | Excel Programming | 0 | 12-23-2014 09:53 PM |
Need help copy and pasting from internet to word, font change sizes. | pearce88 | Word | 3 | 11-19-2009 11:27 PM |