Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 65
end tell
The only difficulty here is in finding the right "autofilter" term. You need to know your VBA well enough to know that the .AutoFilter in the macro is not the Property – which applies to a worksheet and returns the AutoFilter Object for the sheet – but the Method – which applies to a Range. So never mind the autofilter class nor autofilter object property of sheet in Microsoft Excel Suite. Look in the Table Suite, where the class being targeted – range – resides, and you'll find the autofilter range command (analogous to a Method). Everything else is identical.
Finding the last cell in a Range
One frequent need is to find the last used cell in a range, for instance to start a new record. One way is to use the End method:
Dim rNext As Range
With Sheets("Sheet1")
If IsEmpty(.Range("A1").Value) Then
Set rNext = .Range("A1")
Else
Set rNext = .Range("A" & .Range("A" & _
.Rows.Count).End(xlUp).Row).Offset(1, 0)
End If
End With
The welter of nested dots and parentheses gets very difficult to keep straight translating to AppleScript. If you persist, you will find that this is the direct AppleScript translation:
tell application "Microsoft Excel"
tell sheet "Sheet1" of active workbook
if value of range "A1" = "" then
set rNext to range "A1"
else
set rNext to get offset of range ("A" & ¬
(first row index of (get end range ("A" & (count rows)) ¬
direction toward the top))) row offset 1
end if
end tell
end tell
Personally, I would prefer disentangling all that with just a few "ofs" at a time, using intermediate variables along the way, at least until I become very familiar with constructions I run into regularly; something like this:
set lastRowCellA to (get end range ¬
("A" & (count rows)) direction toward the top)
set lastRowNum to (first row index of lastRowCellA)
set lastRowCellAA to range ("A" & lastRowNum)
set rNext to get offset of lastRowCellAA row offset 1
In fact, you can see that by doing this clarifying extraction that there are some redundant and "circular" steps. Once you have lastRowCellA in the first line, you can do the get offset straight away without needing to get the row index and put that back in to the address.
set lastRowCellA to (get end range ¬
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine