如何在excel中对角选择范围?

时间:2012-06-21 20:17:20

标签: excel sap dashboard xcelsius

嗨我有一个简单的问题,如何在excel中对角选择一个范围,让我说我需要选择(a3和b1)或(a3和b2)或简单地a1和b2我需要这个范围用于Sap仪表板设计( xcelsius)并按住控制键不是选项!!

谢谢

2 个答案:

答案 0 :(得分:1)

您无法对角选择范围。 在您的情况下,我认为最好的选择是获得您想要的范围并使用公式复制到列。

例如,如果要选择a1,b2和c3。在单元格d1 put = if(a1 =“”;“”; a1)中,单元格d2 = if(b2 =“”;“”; b2),单元格d3 = if(c3 =“”;“”; c3 )。 然后选择d1到d3。

答案 1 :(得分:0)

我创建了一个userform,可以在任何方向上选择任意数量的单元格。我不知道如何使用它。

Option Explicit
'Run this to open Userform named "Select_Diago"
Sub open_form()
Select_Diago.Show
End Sub

然后会弹出这个东西

enter image description here

输入要选择的单元格数和需要选择的方向(默认设置为向右)

Private Sub Submit_Click()
Dim Direction As String
Select_Diago.Hide
Direction = "SE"
If NE.Value = True Then Direction = "NE"
If SE.Value = True Then Direction = "SE"
If SW.Value = True Then Direction = "SW"
If NW.Value = True Then Direction = "NW"
Call Select_Diagonal(Direction, TextBox1.Value - 1)
End Sub

Sub Select_Diagonal(Direction As String, Num As Integer)
Dim Diagonal As Range, i As Integer
Dim StrEx As String
'Num = InputBox("How Many cells would you like to select diagonally?")
Select Case Direction
Case "SW"
'For SW
For i = 0 To Num
    On Error Resume Next
    StrEx = StrEx + (Split(Cells(, ActiveCell.Column - i).Address, "$")(1)) + CStr((ActiveCell.Row + i)) + ","
Next i
Case "SE"
'For SE
For i = 0 To Num
    On Error Resume Next
    StrEx = StrEx + (Split(Cells(, ActiveCell.Column + i).Address, "$")(1)) + CStr((ActiveCell.Row + i)) + ","
Next i
Case "NE"
'For NE
For i = 0 To Num
    On Error Resume Next
    StrEx = StrEx + (Split(Cells(, ActiveCell.Column + i).Address, "$")(1)) + CStr((ActiveCell.Row - i)) + ","
Next i
Case "NW"
'For NW
For i = 0 To Num
    On Error Resume Next
    StrEx = StrEx + (Split(Cells(, ActiveCell.Column - i).Address, "$")(1)) + CStr((ActiveCell.Row - i)) + ","
Next i
End Select
StrEx = Left(StrEx, Len(StrEx) - 1)
ActiveSheet.Range(StrEx).Select
End Sub

结果1: enter image description here

结果2: enter image description here