Large Formula VBA, but not working

kpmsivaprakasam2003

New Member
Joined
Jan 28, 2020
Messages
14
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
Hi, I am using Excel 2013,

I apply 2 way the Large Formula VBA, but not working, what i am wrong, i don't know

Sub Macro1()
'1st Table Dim statement ---> Declares variables
Dim lRow As Long, lCol As Long
lRow = Range("D5").End(xlDown).Row
lCol = Range("C5").End(xlToRight).Column

'Column Count in Number
Dim k As Long, m As Long
k = Range("C5", Range("C5").End(xlToRight)).Columns.Count
'Row Count in Number
m = Range("D6", Range("D6").End(xlDown)).Rows.Count

Dim MyRange As Range
Set MyRange = Range(Range("D5").Offset(1, k + 3), Range("D5").Offset(m, k + 3))

Range("D5").Offset(2, 1 + 3).Formula = "=LARGE(" & MyRange & ",1)"
'And
'=(LARGE($I$6:$I$12,1)-I7)/2
Range("D5").Offset(2, 1 + 3).Formula = "=(LARGE(" & MyRange & ",1)-" & Range("D5").Offset(1, k + 3) & ")/2"
End Sub

Kindy help me and Thanks for advance
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
your problem is that the range object is very complex object all you want to put in the equation is the range address so change this line

VBA Code:
Range("D5").Offset(2, 1 + 3).Formula = "=(LARGE(" & MyRange & ",1)-" & Range("D5").Offset(1, k + 3) & ")/2"
to
VBA Code:
Range("D5").Offset(2, 1 + 3).Formula = "=(LARGE(" & MyRange.Address & ",1)-" & Range("D5").Offset(1, k + 3) & ")/2"
And similar every were else you are trying to address a range
 
Upvote 0
your problem is that the range object is very complex object all you want to put in the equation is the range address so change this line

VBA Code:
Range("D5").Offset(2, 1 + 3).Formula = "=(LARGE(" & MyRange & ",1)-" & Range("D5").Offset(1, k + 3) & ")/2"
to
VBA Code:
Range("D5").Offset(2, 1 + 3).Formula = "=(LARGE(" & MyRange.Address & ",1)-" & Range("D5").Offset(1, k + 3) & ")/2"
And similar every were else you are trying to address a range
Yes!!! Successfully work, thanks for your support👌👌👌😃😃😃
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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