两列之间的突出显示设置为变量

时间:2016-06-30 03:42:03

标签: vba

1)我试图找到" QTR"然后将此activecell.column设置为变量... 2)然后我按CTRL +右键 3)然后将此activecell.column设置为变量。我需要选择这两列之间的所有列(包括)

 Sub Column()

    Dim cs As Range 'column start
    Dim cst As Range ' column end

    'Find 'QTR'

    Cells.Find(What:="QTR", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=False).Activate
    Set cs = ActiveCell.EntireColumn

    'CTRL + Right Arrow
    Selection.End(xlToRight).Select

    Set cst = ActiveCell.EntireColumn

'highlight all columns from cs column to cst column
    Range(cs & cst).Select



    End Sub

导致n错误。请有人帮忙

1 个答案:

答案 0 :(得分:0)

解决了这个问题

Sub Column()

Dim cs As Integer 'column start
Dim cst As Integer ' column end

'Find 'QTR'

Cells.Find(What:="QTR", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate

cs = ActiveCell.Column

'CTRL + Right Arrow
Selection.End(xlToRight).Select

cst = ActiveCell.Column


Range(Cells.Columns(cs), Cells.Columns(cst)).Select




End Sub