ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Named Columns in a formula within a VBA Macro (https://www.excelbanter.com/excel-programming/437932-using-named-columns-formula-within-vba-macro.html)

ekareem

Using Named Columns in a formula within a VBA Macro
 
Hi,
I have 2 columns, let's say A and B and I named them ColA and ColB
correspondingly.
I want to be able to write something like this:

Question #1:
Cell (10,10) = ColA+ColB

Question #2
ColB = ColA+1

Could some one provide the syntax for each of the above please?

Thank you much
ekareem

JLGWhiz[_2_]

Using Named Columns in a formula within a VBA Macro
 
By my interpretation of the questions:

A#1

ActiveSheet.Cells(10, 10) = WorksheetFunction.Sum(Range("ColA")) _
+
WorksheetFunction,Sum(Range("ColB"))

A#2

Is not logica if ColB is a name for a range of cells, it would generate and
error because it would be attempting to use an Object as a variable in one
case, or attempting to make several cells equal to a single value, which
would also throw an error A named range is nothing more than a string
variable for a range address. Therefore, it must be used in the same manner
as a range address..


"ekareem" wrote in message
...
Hi,
I have 2 columns, let's say A and B and I named them ColA and ColB
correspondingly.
I want to be able to write something like this:

Question #1:
Cell (10,10) = ColA+ColB

Question #2
ColB = ColA+1

Could some one provide the syntax for each of the above please?

Thank you much
ekareem




abu [email protected]

Using Named Columns in a formula within a VBA Macro
 
On Jan 2, 3:04*am, "JLGWhiz" wrote:
By my interpretation of the questions:

A#1

ActiveSheet.Cells(10, 10) = WorksheetFunction.Sum(Range("ColA")) _
* * * * * * * * * * * * * * * * * * * * * * * *+
WorksheetFunction,Sum(Range("ColB"))

A#2

Is not logica if ColB is a name for a range of cells, it would generate and
error because it would be attempting to use an Object *as a variable in one
case, or attempting to make several cells equal *to a single value, which
would also throw an error *A named range is nothing more than a string
variable for a range address. *Therefore, it must be used in the same manner
as a range address..

"ekareem" wrote in message

...



Hi,
I have 2 columns, let's say A and B and I named them ColA and ColB
correspondingly.
I want to be able to write something like this:


Question #1:
Cell (10,10) = ColA+ColB


Question #2
ColB = ColA+1


Could some one provide the syntax for each of the above please?


Thank you much
ekareem- Hide quoted text -


- Show quoted text -


ABOUT Question #1: TRY THIS MAY BE HELPFUL

Sub SUMME()
Dim COLA, COLB As Range
Set COLA = Range("A:A")
Set COLB = Range("B:B")

ActiveSheet.Cells(10, 10) = Application.WorksheetFunction.Sum(COLA) _
+ Application.WorksheetFunction.Sum(COLB)
End Sub


All times are GMT +1. The time now is 03:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com