Using Named Columns in a formula within a VBA Macro

E

ekareem

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
 
J

JLGWhiz

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..
 
A

abu abdullah........halsaeed85

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 inone
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..










- 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top