Hi, the following Excel VBA code is used to select 5 rows by double clicking the cell in the first column corresponding to that row. The code is working fine in excel.
But, I need Access VBA code, which opens the excel file and performs the same function.
Can anyone suggest me how to do this? Thanks in advance!
But, I need Access VBA code, which opens the excel file and performs the same function.
Can anyone suggest me how to do this? Thanks in advance!
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim ColRange As String, PoliciesCount As Integer, LastUsedRow As Long
If Target.Count > 1 Then Exit Sub
If WorksheetFunction.CountA(Cells) > 0 Then
LastUsedRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End If
ColRange = "A2:A" & LastUsedRow
If Intersect(Target, Range(ColRange)) Is Nothing Then Exit Sub
Target.Font.Name = "marlett"
If Target.Value <> "a" Then
PoliciesCount = Columns(1).SpecialCells(xlCellTypeConstants, 23).Cells.Count
If PoliciesCount > 5 Then
MsgBox "You cannot select more than 5 rows", vbOKOnly Or vbCritical, "Warning!"
Exit Sub
End If
Target.Value = "a"
Cancel = True
Exit Sub
End If
If Target.Value = "a" Then
Target.ClearContents
Cancel = True
Exit Sub
End If
End Sub
Comment