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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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