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

从Autocad VBA中查找空单元格

我试图在Excel电子表格中找到第一个空单元格,但我似乎无法通过with语句 我不是一个优秀的程序员,所以我有点迷路了 这是我从网上抓到的代码[代码任何帮助或指导都将不胜感激 

笔友 发表于 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

蛇群 发表于 2006-11-14 13:22:52

您好,Commandor,我不确定它将如何为您工作,乍一看,它似乎是按我的意愿工作的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上测试;J#039~

米粉 发表于 2006-11-14 14:32:44

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

荔枝 发表于 2006-11-14 15:19:56

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

恭帝国 发表于 2006-11-14 15:31:20

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

沙漠泉眼 发表于 2006-11-14 15:39:14

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

伤心俱乐部 发表于 2006-11-14 15:40:11

在这里,我为想象力添加了几个属性,希望这能有所帮助Sub TestFormatACell()
Dim aCell As Range, bCell As Range
Set aCell = ActiveSheet.Range("A1")
Set bCell = Worksheets(3).Cells(1, 2)
aCell.Select
With ActiveCell
.Font.Bold = True
.Font.Italic = True
.Font.Color = RGB(255, 0, 0)
.NumberFormat = "0.0000000"
End With
bCell.Select
With ActiveCell
.VerticalAlignment = xlVAlignCenter
.HorizontalAlignment = xlLeft
.Font.Bold = False
.Font.Italic = False
.Font.Color = RGB(0, 255, 0)
.NumberFormat = "$#,##0.00"
End With
End Sub

~&039;J#039~

个性魅力 发表于 2006-11-14 15:41:33

很酷,但如何将其格式化为#039;文本#039;不是数字?

超级粽子 发表于 2006-11-14 16:04:29

您可以使用以下格式:
.NumberFormat = "@" '' text format 或.NumberFormat = "General" '' general format
~&039;J#039~
页: [1] 2
查看完整版本: 从Autocad VBA中查找空单元格