![]() |
what does target.offset(0,-1).select mean here?
Hi all,
In a small area on my worksheet(A1 to A5), I want to achieve the checklist effect. That means if I double click one of the cell, if the whole area is empty(without "X"), then the clicked cell appeared "X", if there is already "X" in this area, then the doubleclick is ignored, if the clicked cell already is "X" then, "X" will disappear.But without target.offset(),-1).select, "X" will always appear regardless the logics. The following is the code: If CellAddress(target) = I_Zone Or CellAddress(target) = I_Terminal Or CellAddress(target) = I_Yard Or _ CellAddress(target) = I_Subdivision Or CellAddress(target) = I_Passenger Then Dim bCheckMarkAlreadyExist As Boolean Dim bOldEnableEventState As Boolean bCheckMarkAlreadyExist = Trim(Range(I_Zone).Value) = "X" Or Trim(Range(I_Terminal).Value) = "X" Or Trim(Range(I_Yard).Value) = "X" Or _ Trim(Range(I_Subdivision).Value) = "X" Or Trim(Range(I_Passenger).Value) = "X" If bCheckMarkAlreadyExist And Trim(target.Value) < "X" Then ' x, o MsgBox "Only One Item Can Be Picked Up", vbInformation Cancel = True ElseIf bCheckMarkAlreadyExist And Trim(target.Value) = "X" Then '(xo) bOldEnableEventState = Application.EnableEvents Application.EnableEvents = False target.Value = "" Cancel = False Application.EnableEvents = bOldEnableEventState ElseIf Not bCheckMarkAlreadyExist Then bOldEnableEventState = Application.EnableEvents Application.EnableEvents = False target.Value = "X" Cancel = False Application.EnableEvents = bOldEnableEventState End If target.offset(0, -1).Select ' ?????????????? End If Clara -- thank you so much for your help |
what does target.offset(0,-1).select mean here?
target.offset(0,-1).select means select cell 1 column to left same row
i think this code do what u mean - not sure :-) Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Intersect(Target, Range("A1:A5")) Is Nothing Then Exit Sub If Target = "X" Then Target = "": Exit Sub If Target = "" And Application.WorksheetFunction.CountA(Range("A1:A5" ), "X") <= 1 Then Target.Value = "X" End If End Sub "clara" skrev: Hi all, In a small area on my worksheet(A1 to A5), I want to achieve the checklist effect. That means if I double click one of the cell, if the whole area is empty(without "X"), then the clicked cell appeared "X", if there is already "X" in this area, then the doubleclick is ignored, if the clicked cell already is "X" then, "X" will disappear.But without target.offset(),-1).select, "X" will always appear regardless the logics. The following is the code: If CellAddress(target) = I_Zone Or CellAddress(target) = I_Terminal Or CellAddress(target) = I_Yard Or _ CellAddress(target) = I_Subdivision Or CellAddress(target) = I_Passenger Then Dim bCheckMarkAlreadyExist As Boolean Dim bOldEnableEventState As Boolean bCheckMarkAlreadyExist = Trim(Range(I_Zone).Value) = "X" Or Trim(Range(I_Terminal).Value) = "X" Or Trim(Range(I_Yard).Value) = "X" Or _ Trim(Range(I_Subdivision).Value) = "X" Or Trim(Range(I_Passenger).Value) = "X" If bCheckMarkAlreadyExist And Trim(target.Value) < "X" Then ' x, o MsgBox "Only One Item Can Be Picked Up", vbInformation Cancel = True ElseIf bCheckMarkAlreadyExist And Trim(target.Value) = "X" Then '(xo) bOldEnableEventState = Application.EnableEvents Application.EnableEvents = False target.Value = "" Cancel = False Application.EnableEvents = bOldEnableEventState ElseIf Not bCheckMarkAlreadyExist Then bOldEnableEventState = Application.EnableEvents Application.EnableEvents = False target.Value = "X" Cancel = False Application.EnableEvents = bOldEnableEventState End If target.offset(0, -1).Select ' ?????????????? End If Clara -- thank you so much for your help |
All times are GMT +1. The time now is 11:53 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com