나는 현재 날짜가있는 테이블의 열을 비교하고 참이면 강조 표시하는 VBA를 작성하려고합니다.엑셀 VBA의 현재 날짜가있는 테이블 열을 비교하십시오.
내가 일하고 있어요 코드는 다음과 같습니다 :
Private Sub Workbook_Open()
Dim tbl As Excel.ListObject 'Table name
Dim lr As Excel.ListRow 'Row index
Dim ws As Excel.Worksheet 'Work sheet
'column names
Dim keepInTouch As Range, invite As Range, present As Range, follow As Range
Set ws = ThisWorkbook.Worksheets(1) 'select work book index 1
Set tbl = ws.ListObjects("ContactList") 'set ContactList to tbl
Set keepInTouch = tbl.ListColumns("Keep in Touch").DataBodyRange 'Select the appropreate header
Set invite = tbl.ListColumns("Invite").DataBodyRange
Set present = tbl.ListColumns("Present").DataBodyRange
Set follow = tbl.ListColumns("Follow").DataBodyRange
'MsgBox tbl
For Each lr In tbl.ListRows
If lr.Range(1, tbl.ListColumns("Keep in Touch").Index).Value <> Date Then
keepInTouch.Interior.ColorIndex = xlNone
keepInTouch.Font.ColorIndex = 1
keepInTouch.Font.Bold = False
'If keepInTouch(1).Value = Date And keepInTouch(1).Value <> "" Then
ElseIf lr.Range(1, tbl.ListColumns("Keep in Touch").Index).Value = Date Then
keepInTouch.Interior.ColorIndex = 3
keepInTouch.Font.ColorIndex = 2
keepInTouch.Font.Bold = True
End If
Next lr
End Sub
행 19 :
Run time error '438':
Object doesn't support this property or method.
무엇
원인If keepInTouch.Index = Date And keepInTouch.Index <> "" Then
여기
는 예를 들어 테이블 이렇게하는 올바른 방법? 예를 들어
lr.Range(1, 2)
두 번째 열의 셀 [조건부 서식 (https://www.ablebits.com/office-addins-blog/와 쉬울 말아야 2014/06/17/excel-conditional-formatting-dates/# based-current-date) Range는'.Index'를 가지지 않습니다 .. 아마도'.Value'를 의미 할 것입니다 – Slai
@Slai'.Value'를 시도했지만 실행 시간 오류 '13': 유형 불일치' – Amir
'If keepInTouch (1) .Value = Date Then '을 사용하십시오. 이미 길이가 0인지 확인하기 위해 길이가 0 인 문자열을 확인할 필요가 없습니다. 현재 날짜. – Jeeped