공개를 필수 컴파일 나는 대부분의 종류의 코딩에서 상당히 경험이 있어요하지만 그 뒤에 논리의 합리적인 이해하고 자주 단지 구문의 권리 등VBA 엑셀은 - 오류 개체
을 받고있는 약간의 압력이 필요합니다나는 이전하지만 다른 문제에 동일한 코드를 게시하지 않고 나는 그것이
목적을 위해 가장 새로운 질문을 만들 생각 때문에 더는이 문제를 발견했습니다 :가 난 할 노력하고있어 것은 만드는 것입니다 상단 행을 가로 지르는 연속적인 다 (da)의 목록 인 스프레드 시트 테. 처음 몇 줄에는 청구서 등의 데이터가 있습니다. 제가 수행하기를 원하는 매크로는 청구서 금액, 청구서의 시작과 종료 날짜 및 청구서 수 (주별/월별 등)를 살펴본 다음에 셀을 채 웁니다. 계산서가 만기가되는 날짜의 란에있는 같은 행. 나는이 코드를 다룰 마지막 날을 보냈고 나는 그것을 실행하기까지는 꽤 행복했다. 나는 이미 변수를 사용하고있는 몇 가지 버그를 없앴습니다. 분명히 존재하지 않는 값과 셀 (행, 열)에 대한 구문을 엉망으로 만들었습니다.
지금에 올라오고있어 문제는 컴파일 오류입니다 :이 라인에 필요한 개체 :
Set dateAddress = Range("J1:AAI1").Find(currentDate, LookIn:=xlValues).Address
'find the current date within the range of dates in row 1
그 라인의 첫 번째 행에있는 모든 기간에 걸쳐 검색하는 일을 할 예정이다 무엇 그 다음 'currentDate'를 저장 한 다음 dateAddress로 저장하여 다음 코드 줄에서 currentRow와 함께 dateAddress.Column을 사용하여 청구 금액으로 채울 오른쪽 셀을 찾습니다.
충분히 명확합니까? 내 코드는 아래와 같습니다.
내 코드 : 당신이 set
를 사용할 필요가 없습니다
Private Sub CommandButton1_Click()
Dim currentDate As Date
Dim currentRow As Integer
Dim repeatuntilDate As Date
Dim repeatuntilRow As Integer
Dim dateAddress As Date
currentRow = 3 'First row of entries
repeatuntilRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row 'Last row of entries
While currentRow < repeatuntilRow 'Loop from first row until last row of entries
currentDate = Cells(currentRow, "G").Value 'Set Start Date
repeatuntilDate = Cells(currentRow, "H").Value 'Set End Date
While currentDate <= repeatuntilDate 'Loop from Start Date until End Date
Set dateAddress = Range("J1:AAI1").Find(currentDate, LookIn:=xlValues).Address 'find the current date within the range of dates in row 1
Cells("dateAddress.Column,currentRow").Value = Cells("D,currentRow").Value 'Populate cell with amount
'Increment the currentDate by the chosen frequency
If Cells(currentRow, "E").Value = "Weekly" Then
currentDate = DateAdd("ww", 1, currentDate)
ElseIf Cells(currentRow, "E").Value = "Fortnightly" Then
currentDate = DateAdd("ww", 2, currentDate)
ElseIf Cells(currentRow, "E").Value = "Monthly" Then
currentDate = DateAdd("m", 1, currentDate)
ElseIf Cells(currentRow, "E").Value = "Quarterly" Then
currentDate = DateAdd("q", 1, currentDatee)
ElseIf Cells(currentRow, "E").Value = "6 Monthly" Then
currentDate = DateAdd("m", 6, currentDate)
ElseIf Cells(currentRow, "E").Value = "Annually" Then
currentDate = DateAdd("y", 1, currentDate)
' ElseIf Cells(currentRow,"E").Value = "Once off" Then
' Exit While
End If
Wend
currentRow = currentRow + 1 'Once row is complete, increment to next row down
Wend
End Sub
감사합니다. simpLE MAn. 내가 잘못하고있는 것이 몇 가지 있었다. (작동하는) 내 최종 코드는 다음과 같습니다. '범위 포함 ("J1 : AAI1") lastDate = .Cells (.Cells.Count) '설정 lastDate에서 시작될 다음 찾기 설정 끝내기 집합 dateRange = Range ("J1 : AAI1"). Find (What : = currentDate, After : = lastDate)' – Bzmek