how to select a range dynamic of cells

682 views
Skip to first unread message

grendo

unread,
Jul 19, 2011, 9:02:23 AM7/19/11
to Excel-DNA
Hi,
I am trying to work out how to do the following

if I have some cells like

a b c d
1 2 3 4
4 5 6 7

8 9 0 0

I want to select cell a then select a range that goes from cell a to
cell 7 the same way as you click on cell a and hit Ctrl+a, (ie it will
not select cells 8,9,0,0 because there is a empty row in between.
After I select the range I want to clear it.

trying some code like

ExcelReference firstCell = new ExcelReference(cells.RowFirst,
cells.RowFirst, cells.ColumnFirst, cells.ColumnFirst, cells.SheetId);
string firstCellSheet = (string)XlCall.Excel(XlCall.xlSheetNm,
firstCell);
XlCall.Excel(XlCall.xlcWorkbookSelect, new object[]
{ firstCellSheet });
object oldSelectionOnArraySheet = XlCall.Excel(XlCall.xlfSelection);
XlCall.Excel(XlCall.xlcFormulaGoto, firstCell);
XlCall.Excel(XlCall.xlcSelectAll);
ExcelReference oldArray =
(ExcelReference)XlCall.Excel(XlCall.xlfSelection);
oldArray.SetValue(ExcelEmpty.Value);

can anyone point me to where I get some doco on how to use the
xlcSelect commands or some sample code ?

Govert van Drimmelen

unread,
Jul 19, 2011, 4:30:39 PM7/19/11
to Excel-DNA
Hi,

You can download the official help file (XLMACR8.HLP) for the Excel
Macro language from here:
=http://www.microsoft.com/downloads/details.aspx%3Fdisplaylang%3Den
%26FamilyID%3D94be9dfa-8a84-4155-b75f-f29b15d5629f
or here
http://support.microsoft.com/kb/128185/en-us.

You're looking for SELECT.SPECIAL (xlcSelectSpecial), option 5
(Current Region). I paste the help content below.
Maybe:

XlCall.Excel(XlCall.xlcSelectSpecial, 5);
ExcelReference oldArray =
(ExcelReference)XlCall.Excel(XlCall.xlfSelection);

-Govert

===================================================
SELECT.SPECIAL

Equivalent to choosing the Go To command from the Edit menu and then
selecting the Special button. Use SELECT.SPECIAL to select groups of
similar cells in one of a variety of categories.

Syntax

SELECT.SPECIAL(type_num, value_type, levels)
SELECT.SPECIAL?(type_num, value_type, levels)

Type_num is a number from 1 to 13 corresponding to options in the
Go To Special dialog box and describes what to select.

Type_num Description

1 Notes/comments
2 Constants
3 Formulas
4 Blanks
5 Current region
6 Current array
7 Row differences
8 Column differences
9 Precedents
10 Dependents
11 Last cell
12 Visible cells only (outlining)
13 All objects

Value_type is a number specifying which types of constants or
formulas you want to select. Value_type is available only when
type_num is 2 or 3.

Value_type Selects

1 Numbers
2 Text
4 Logical values
16 Error values

These values can be added to select more than one type. The default
for value_type is 23, which select all value types.

Levels is a number specifying how precedents and dependents are
selected. Levels is available only when type_num is 9 or 10. The
default is 1.

Levels Selects

1 Direct only
2 All levels
Reply all
Reply to author
Forward
0 new messages