Kayote
Kayote

Reputation: 15627

Excel VBA - passing argument to property

In Excel VBA, Im trying to pass an argument value to property 'VerticalAlignment'. The error I get is: "Unable to set the HorizontalAlignment property of the Range class". Clearly the problem is with the 'horzAlign' & 'vertAlign' values, however, what?

' Merge the range & horizontal & vertical
' alignment as per arguments
Sub mergeCellsWithLeftAlign(ByVal curRange As Range, _
    ByVal horzAlign As String, ByVal vertAlign As String)

        With curRange
            .HorizontalAlignment = horzAlign
            .VerticalAlignment = vertAlign
            .MergeCells = True
        End With
End Sub

This is being called in another procedure like this:

Call mergeCellsWithLeftAlign(Range("F10:F11"), "xlLeft", "xlBottom")

Upvotes: 1

Views: 872

Answers (3)

psychicebola
psychicebola

Reputation: 949

according to msdn, the property values must be one of these:

horizontal:

  • xlCenter
  • xlDistributed
  • xlJustify
  • xlLeft
  • xlRight

vertical:

  • xlBottom
  • xlCenter
  • xlDistributed
  • xlJustify
  • xlTop

Upvotes: 0

iDevlop
iDevlop

Reputation: 25262

RTFM. From the help:

The value of this property can be set to one of the following constants:

xlBottom xlCenter xlDistributed xlJustify xlTop

Upvotes: 0

Paul Ogilvie
Paul Ogilvie

Reputation: 25286

Looking at the VBA Help the values must not be "xlLeft", "xlBottom" but xlLeft, xlBottom, i.e. without the quotes - they are integer constants.

Upvotes: 7

Related Questions