1

I hoped and guessed we could probably have something like this:

ws.Range("D").VerticalAlignment

Which appeared to be wrong a bit later.

Edit: previously in question I mentioned:

ws.Range("A:F").VerticalAlignment

And given a feedback which mentioned that was correct.

As you might see, I'm going to select the whole columns of A to F, what could be the right way doing so?

Kasrak
  • 1,509
  • 4
  • 24
  • 48

3 Answers3

2

Hi this confused me a bit when I needed to do it as well. I'll do my best to explain!

You can select single cells (still classed as a Range I believe) using

WorkSheet.Cells[row, column]

To select multiple Cells you could do something like this

Range startCell = excelSheet.Cells[1,1];
Range endCell = excelSheet.Cells[3,3];
Range myCellCollection = excelSheet.Range[startCell, endCell];

Hope that helps a bit!

Let me know if you want any more clarification, it may not be the most efficient way but it is still running in my application :)

Numli
  • 407
  • 1
  • 4
  • 10
1

As you have done is fine, but you haven't passed an argument to VerticalAlignment, assuming ws is set correctly too.

Range("D:D").VerticalAlignment = xlVAlignCenter
Range("A:F").VerticalAlignment = xlVAlignTop

As a few examples.

Tim Wilkinson
  • 3,761
  • 11
  • 34
  • 62
-3

How about selecting A1:F1 then use

activecell.EntireColumn.select();
Ali BAGHO
  • 358
  • 6
  • 17