Macro - Run in a different cell selected by user each time

AniR

New Member
Joined
Oct 3, 2021
Messages
6
Hello, I do not know VBA can someone please help to edit below code so that the macro runs in a different cell (cell of users choice) each time. Currently it repeats itself in the same cell. Thanks in advance.

Sub UnitPrice()
'
' UnitPrice Macro
'
' Keyboard Shortcut: Ctrl+u
'
ActiveWindow.SmallScroll Down:=-9
Range("B106:M111").Select
Selection.Copy
ActiveWindow.ScrollRow = 103
ActiveWindow.ScrollRow = 102
ActiveWindow.ScrollRow = 100
ActiveWindow.ScrollRow = 99
ActiveWindow.ScrollRow = 98
ActiveWindow.ScrollRow = 96
ActiveWindow.ScrollRow = 27
ActiveWindow.ScrollRow = 26
ActiveWindow.ScrollRow = 22
ActiveWindow.ScrollRow = 9
Range("B10").Select
ActiveSheet.Paste
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Welcome to MrExcel Message Board.
Please update your Account Details Also.
Try:
VBA Code:
Sub UnitPrice()
' UnitPrice Macro
' Keyboard Shortcut: Ctrl+u
Range("B106:M111").Copy Range("B10")
End Sub

OR
VBA Code:
Sub UnitPrice()
' UnitPrice Macro
' Keyboard Shortcut: Ctrl+u
Range("B10:M15").Value = Range("B106:M111").Value
End Sub
 
Upvote 0
Welcome to the MrExcel board!

Can you give some specific examples of what you mean by this?
the macro runs in a different cell (cell of users choice) each time.
Give examples of what cell(s) the user is selecting and what should be copied from where to where.
 
Upvote 0
Welcome to MrExcel Message Board.
Please update your Account Details Also.
Try:
VBA Code:
Sub UnitPrice()
' UnitPrice Macro
' Keyboard Shortcut: Ctrl+u
Range("B106:M111").Copy Range("B10")
End Sub

OR
VBA Code:
Sub UnitPrice()
' UnitPrice Macro
' Keyboard Shortcut: Ctrl+u
Range("B10:M15").Value = Range("B106:M111").Value
End Sub
I do not know VBA (so that makes things worse) although I did copy and paste the recommended code. Thanks for the help. It did not serve my purpose. Perhaps I did not explain my requirement clearly.
 
Upvote 0
Welcome to the MrExcel board!

Can you give some specific examples of what you mean by this?

Give examples of what cell(s) the user is selecting and what should be copied from where to where.
Basically I need a range of cells to be copied and pasted in any cell that user (I) clicks each time I run the macro. Thanks
 
Upvote 0
is this what you are looking for
VBA Code:
Range("B6:M11").Copy ActiveCell
 
Upvote 0
Solution
it should stay if below is the only line in your macro
VBA Code:
Range("B6:M11").Copy ActiveCell
do you have anything else after
 
Upvote 0
it should stay if below is the only line in your macro
VBA Code:
Range("B6:M11").Copy ActiveCell
do you have anything else after
No. Also if I delete cells in the sheet the cell reference for the cells to copy changes each time. Is there any way to lock them so that it is the same range that is copied each time?
 
Upvote 0

Forum statistics

Threads
1,215,501
Messages
6,125,169
Members
449,212
Latest member
kenmaldonado

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