Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2019, 06:05 AM
taryn taryn is offline Copy row and change details Windows 10 Copy row and change details Office 2016
Novice
Copy row and change details
 
Join Date: Jan 2015
Location: Gibraltar
Posts: 21
taryn is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 10-02-2019, 08:58 AM
Logit Logit is offline Copy row and change details Windows 10 Copy row and change details Office 2007
Expert
 
Join Date: Jan 2017
Posts: 529
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

.
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
Reply With Quote
  #3  
Old 10-03-2019, 03:11 AM
taryn taryn is offline Copy row and change details Windows 10 Copy row and change details Office 2016
Novice
Copy row and change details
 
Join Date: Jan 2015
Location: Gibraltar
Posts: 21
taryn is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 10-03-2019, 08:15 AM
Logit Logit is offline Copy row and change details Windows 10 Copy row and change details Office 2007
Expert
 
Join Date: Jan 2017
Posts: 529
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

.
This line was commented out :

'Rows("13:13").Select
Reply With Quote
  #5  
Old 11-07-2019, 05:58 AM
taryn taryn is offline Copy row and change details Windows 10 Copy row and change details Office 2016
Novice
Copy row and change details
 
Join Date: Jan 2015
Location: Gibraltar
Posts: 21
taryn is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 11-07-2019, 06:56 AM
Logit Logit is offline Copy row and change details Windows 10 Copy row and change details Office 2007
Expert
 
Join Date: Jan 2017
Posts: 529
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Glad you found an answer. Cheers !
Reply With Quote
Reply

Thread Tools
Display Modes


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
Copy row and change details Need help copy and pasting from internet to word, font change sizes. pearce88 Word 3 11-19-2009 11:27 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:37 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft