Fatty 发表于 2006-11-14 11:04:51

从Autocad VBA中查找空单元

我试图在excell电子表格中找到第一个空单元格,但我似乎无法通过with语句。 我不是一个优秀的程序员,所以我有点迷失了。 这是我从互联网上抓取的代码
Sub FindLastCell()
Dim LastCell As Range
With ActiveSheet
    Set LastCell = .Cells(.Rows.Count, "A").End(xlUp)
    If IsEmpty(LastCell) Then
      'do nothing
    Else
      Set LastCell = LastCell.Offset(1, 0)
    End If
End With
MsgBox LastCell.Row
End Sub
任何帮助或指导将不胜感激
**** Hidden Message *****

Fatty 发表于 2006-11-14 12:41:08

这就是我想到的
Public Function GetLastRow() As Long
Dim wks As Excel.worksheet
Const BottomRowNum = 65536
    Set wks = objExcel.ActiveSheet
    Dim i As Long
    For i = 1 To BottomRowNum
      If IsEmpty(wks.Cells(i, 2)) Then
            GetLastRow = i - 1
            Exit Function
      End If
    Next
    GetLastRow = BottomRowNum
End Function

Bryco 发表于 2006-11-14 13:22:52

您好,指挥官<br>不确定它将如何为您工作<br>乍一看,似乎已按我的意愿工作<br><pre>Option Explicit
'' ~~~~~~~~~~~~~~~~''
Function FindLastRow()
Dim LastRow As Range

With ActiveSheet
    Set LastRow = .Cells.SpecialCells(xlCellTypeLastCell)
      LastRow.Activate
End With
FindLastRow = LastRow.Row
End Function
'' ~~~~~~~~~~~~~~~~''
Function FindLastColumn() As Long
Dim LastColumn As Range

With ActiveSheet
    Set LastColumn = .Cells.SpecialCells(xlCellTypeLastCell)
      LastColumn.Activate
End With
FindLastColumn = LastColumn.Column

End Function
'' ~~~~~~~~~~~~~~~~''
Sub FindLastCell()
Dim LastCell As Range
With ActiveSheet
Set LastCell = .Cells(FindLastRow, FindLastColumn)
End With
LastCell.Activate
MsgBox "Last Cell Address: " & vbCr & LastCell.Address

End Sub

仅在Excel2003上测试
Hth
~'J'~

Fatty 发表于 2006-11-14 14:32:44

好的,你知道如何从autocad中格式化单元格吗?

Fatty 发表于 2006-11-14 15:19:56

您到底想要什么,
格式化单元格中的文本,即设置粗体、斜体、颜色等,还是需要格式化
值,即常规、文本、数字格式设置等
~'J'~

Dnereb 发表于 2006-11-14 15:31:20

设置值格式,如文本或数字,带0位小数

Fatty 发表于 2006-11-14 15:39:14

CmdrDuh,有时在excel中启动子对象更容易,这样您就可以查看所有可用的特性,然后将其放入autocad vba中。我这样说只是因为我也不是一个优秀的程序员。

Arizona 发表于 2006-11-14 15:40:11

在这里我为想象添加了几个属性
希望这有助于
~'J'~

Bryco 发表于 2006-11-14 15:41:33

酷,但是你如何把它格式化成“文本”而不是数字呢?

Fatty 发表于 2006-11-14 16:04:29

您可以使用以下格式:
.NumberFormat = "@" '' text format

.NumberFormat = "General" '' general format
~'J'~
页: [1] 2
查看完整版本: 从Autocad VBA中查找空单元