Cell formula promlem - Excel macro

AI Thread Summary
The discussion centers around troubleshooting a macro code issue in Excel where a "##Name" error occurs due to improperly defined formulae. The user is attempting to utilize a dynamic range called "Patientrange" in various statistical functions but encounters errors. Suggestions from other participants include checking the initialization of the variable "Infocol" and dropping the ".Address" from range specifications. Ultimately, the user discovers that the correct way to reference the dynamic range in the formula is to concatenate it into the string, changing the formula from ActiveCell.Formula = "=MEDIAN(Patientrange)" to ActiveCell.Formula = "=MEDIAN(" & Patientrange & ")". This adjustment resolves the issue with the formula not working as intended.
big man
Messages
241
Reaction score
0
Hi

I have been having a problem with a section of my code in the macro that I've created. The problem is that the formulae that I want to use aren't working and soe I get a "##Name" error in the cells where the formula is supposed to have worked.

Patientrange = Range(PatAgeLet & "2" & ":" & PatAgeLet & Locator).Address
For Count = 2 To 6
FormulaRange1 = Range(Infocol & Count).Offset(0, 1).Address
FormulaRange2 = Range(Infocol & Count).Offset(0, 2).Address
NewRange = Range(FormulaRange1 & ":" & FormulaRange2).Select
With Selection
.NumberFormat = "0"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
If Count = 2 Then
ActiveCell.Formula = "=MIN(PatientRange)"
ElseIf Count = 3 Then
ActiveCell.Formula = "=MAX(Patientrange)"
ElseIf Count = 4 Then
ActiveCell.Formula = "=MEDIAN(Patientrange)"
ElseIf Count = 5 Then
ActiveCell.Value = Rangarrsize
ElseIf Count = 6 Then
ActiveCell.Formula = "=COUNTIF(Patientrange, ""<=40"")"
End If
Next Count

As you can see by this code Patientrange is a dynamic range and so this is the range that I want to use in my formulae. However, it just isn't working at all.

Any suggestions??
 
Technology news on Phys.org
Try dropping the .address from your range specifications.

I do not see where you have initialized Infocol.

Do not give up keep reading the help on how to specify a range.
 
Thanks for the reply Integral. Sorry about that but I was only providing a segment of the code so that's why you saw that infocol wasn't initialised.

I'm not sure if you're interested at all, but I found out what the problem was. When you specify the formula with the dynamic range you must put the dynamic range in quotes so instead of having ActiveCell.Formula = "=MEDIAN(Patientrange)" you must have ActiveCell.Formula = "=MEDIAN(" & Patientrange & ")".
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top