0

在这里寻求一点帮助。我试图让我的宏将仅包含其中信息的单元格的值粘贴到列表中。不幸的是,我的宏也拉出了所有空单元格,但将它们粘贴为空单元格。有谁知道如何让我的宏完全忽略空单元格?另外,我正在尝试将此宏粘贴到 C38,但我认为我的引用可能搞砸了..

Range("C11").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "3"
Range("C12").Select
SolverOk SetCell:="$A$20", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$26:$V$29", _
    Engine:=2, EngineDesc:="Simplex LP"
SolverOk SetCell:="$A$20", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$26:$V$29", _
    Engine:=2, EngineDesc:="Simplex LP"
SolverSolve UserFinish:=True
        iMaxRow = 17
For iCol = 3 To 21
For iRow = 1 To iMaxRow

With Worksheets("Summary").Cells(iRow, iCol)
    ' Check that cell is not empty.
    If .Value = "" Then
        'Nothing in this cell.
        'Do nothing.
    Else
        ' Copy the cell to the destination
        Worksheets("Summary").Cells(3, 38).Value = .Value
    End If
End With

Next iRow
Next iCol

Sheets("Summary").Select
4

2 回答 2

1

试试这个:

Sub tgr()

    Dim ws As Worksheet
    Dim rIndex As Long
    Dim cIndex As Long

    Set ws = Sheets("Summary")

    Range("C11").Value = "3"
    SolverOk SetCell:="$A$20", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$26:$V$29", _
             Engine:=2, EngineDesc:="Simplex LP"
    SolverSolve UserFinish:=True

    For cIndex = Columns("C").Column To Columns("U").Column
        For rIndex = 1 To 17
            If Len(Trim(ws.Cells(rIndex, cIndex).Text)) > 0 Then
                ws.Cells(Rows.Count, "C").End(xlUp).Offset(1).Value = ws.Cells(rIndex, cIndex).Text
            End If
        Next rIndex
    Next cIndex

    ws.Select

    Set ws = Nothing

End Sub
于 2013-08-13T15:52:08.897 回答
0

如果您想将所有内容保存在单元格(“C38”)中,那么您应该使用这一行

Worksheets("Summary").Cells(3, 38).Value = Worksheets("Summary").Cells(3, 38).Value + .Value + chr(11)
于 2013-08-13T13:47:07.933 回答