How to run macro only selected rows

Anbuselvam

Board Regular
Joined
May 10, 2017
Messages
97
Hi

I have recorded the macro to run the calculation steps as below.


Sub Run_Calc()'
' Run_Calc Macro
'
' Keyboard Shortcut: Ctrl+g
'
Range("S2:DK2").Select
Selection.Copy
Range("S8:DK10100").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Calculate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Calculate
Range("C7").Select
Selection.End(xlDown).Select
End Sub



By running the above macro, sheet got calculated S8 to DK10100.

My desired result is,

The above function should run only the number of rows I have selected instead of S8 to DK10100.

For Example, If I run the macro while selecting the Row number 500 to 550, Then it should calculate S500 to DK550 only.

How do I change them to get desired results?

Expecting positive reply. Thanks in Advance.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Alas, there's no way to calculate arbitrary range. Either everything is calculated or none (although there's option to calculate except Data Tables, but this is irrelevant to your need).
 
Upvote 0
Hi

Please check the below code, which is working only in the last row of the sheet and while selecting the last cell of I row. My desired result is not only the last row, from first to last any row it should work.

If possible please check and guide for further.

Sub Run_Calc()
'
' Run_Calc Macro
'
' Keyboard Shortcut: Ctrl+g
'
Dim lr As Integer
lr = Range("A" & Rows.Count).End(xlUp).Row
If ActiveCell.Row <> lr Then Exit Sub
lr = lr + 1
Range("S2:DK2").Copy
Range("S" & lr & ":DK" & lr).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False
Application.CutCopyMode = False
Calculate
Range("C" & lr).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,613
Members
449,238
Latest member
wcbyers

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