2015-11-09 13 views
5

Bir satır, hangi satır içinde olduğunu belirlemek yardımcı olan bu kod bloğum var. Ancak, yukarıdaki satırı gizlediğimde, düğme gizli satır başvuruyor. ÖrneğinDüğme excel içinde yanlış satır başvuruyor

: düğmesi satırda 20 ve ben hem satırları 19 ve 18, düğme döner satır Gerçekten garip 18.

gizlerseniz ben düğme döner satır 19. tıklayarak, satır 19 gizlemek durumunda. İşte

Ben düğmesi oluşturmak için kullanılan bloktur:

Sub AddButtons() 
    Dim button As button 
    Application.ScreenUpdating = False 

    Dim st As Range 
    Dim sauce As Integer 

    For sauce = 10 To Range("F" & Rows.Count).End(xlUp).Row Step 1 
    Set st = ActiveSheet.Range(Cells(sauce, 11), Cells(sauce, 11)) 
    Set button = ActiveSheet.Buttons.Add(st.Left, st.Top, st.Width, st.Height) 

    With button 
     .OnAction = "GoToIssue.GoToIssue" 
     .Caption = "Go To Source" 
     .Name = "Button" & sauce 
    End With 
    Next sauce 
    Application.ScreenUpdating = True 
End Sub 

Ve burada tıklandığında kez düğmeye satır kimliği döndürür blok:

Sub GoToIssue() 

    Dim b As Object 
    Dim myrow As Integer 

    Dim hunt As String 

    Set b = ActiveSheet.Buttons(Application.Caller) 
    With b.TopLeftCell 
     myrow = .Row 

    End With 


    hunt = Worksheets("Dummy").Range("F" & myrow).Value 

    'MsgBox hunt 

End Sub 

Kişisel zaman ve yardım takdir edilir.

Public Function FindButtonRow(btn As Object) As Long 
    Dim cell As Excel.Range 
    '------------------------------------------------- 

    Set cell = btn.TopLeftCell 

    Do While cell.EntireRow.Hidden 
     Set cell = cell.Offset(1, 0) 
    Loop 

    FindButtonRow = cell.row 

End Function 

O TopLeftCell yöntemi tarafından döndürülen hücre gizli satırda bulunmayan denetler eğer:

+0

Eğer 'BottomRightCell' denediniz mi? Görünüşe göre, düğmenin boyutuna ve nasıl uzandığına bağlı. Sadece bir grup test yaptım ve 'Görünür' hücrelerini gösterme açısından 'BottomRightCell' daha güvenilir görünüyor. –

cevap

2

Bu işlevi kullanabilirsiniz. Öyleyse, işlev, hücreyi gizlenmemiş satırdan bulduğu sürece aşağıdaki hücreyi çalıştırır.


Öylece GoToIssue senin değişmezde kullanabilirsiniz:

Sub GoToIssue() 

    Dim b As Object 
    Dim myrow As Integer 

    Dim hunt As String 

    Set b = ActiveSheet.Buttons(Application.Caller) 
    myrow = FindButtonRow(b) 

    hunt = Worksheets("Dummy").Range("F" & myrow).Value 

    'MsgBox hunt 

End Sub 
+0

Bir çekicilik gibi çalışır! teşekkür ederim – Amostafa

İlgili konular