2014-04-20 3 views
0

Ive는 수 시간 동안 검색 되었기 때문에 VBA에 대한 지식은 매우 제한되어 있으므로 손실에 처해 있습니다. 나는 맨 왼쪽 (1 열)의 업데이트 날짜와 함께 아래 라인에 플러스 또는 마이너스 금액을 입력하여 업데이트되는 맨 위 행 (행 B)을 가로 질러가는 여러 항목에 대해 "인벤토리 합계"를 가지고 있습니다. 나는 각 달마다 뺄셈 만 추적 할 필요가있는 또 다른 책을 가지고있다.총 월간 가치는 VBA를 능가합니다.

이미 (auto_run) 매크로가 있으므로이 매크로를 추가 할 계획입니다. 오늘 날짜를 확인하고 그 달의 첫 번째 달이 그 달의 모든 음수 (열당)를 합하여 다른 책의 맨 윗줄에 추가하는지 확인해야합니다.

제가 알아야 할 부분은 VBA에서 매월 합계를 얻는 방법입니다.

이 내가 오늘 날짜를 확인하기 위해 사용하고 무엇을 : 나는 지난 달의 첫 번째와 마지막 달 말 사이의 값에 대한 중첩 된 IF 검사 같은 것을 생각하고

If Date - Day(Date) + 1 = Date - Day(Date) + 1 And Range("'Monthly Office Inventory'!A2") <> Date - Day(Date) + 1 Then 

, 날짜 기능을 사용합니다.

도와주세요.

+0

내가 필요한 것은 날짜별로 행을 검색하고 지난 달에 속하는 모든 데이터를 선택하는 방법입니다. – Heroz

답변

0
Sub Datetest() 
Dim i As Integer 
Dim x As Integer 
Dim rng1 As Range 
Dim rng2 As Range 
Dim crninvbk As Worksheet 
Dim mntlisbk As Worksheet 
Set crninvbk = Worksheets("Current Office Inventory") 
Set mntlisbk = Worksheets("sheet1") 
PreviousMonth = DateAdd("m", -1, Date) 
Negativemonthly = 0 

For x = 2 To 23 
    For i = 3 To 100 
     If crninvbk.Cells(i, 1).value >= dhFirstDayInMonth And crninvbk.Cells(i, 1).value <= dhLastDayInMonth Then 
      If crninvbk.Cells(i, x).value < 0 Then 
      Negativemonthly = Negativemonthly + crninvbk.Cells(i, x).value 
      End If 
     End If 
    Next i 
    mntlisbk.Cells(2, x) = Negativemonthly 
    MsgBox (Negativemonthly) 
    Negativemonthly = 0 
Next x 
MsgBox (Negativemonthly) 

End Sub 
Function dhFirstDayInMonth(Optional dtmDate As Date = 0) As Date 
    ' Return the first day in the specified month. 
    PreviousMonth = DateAdd("m", -1, Date) 
    dhFirstDayInMonth = DateSerial(Year(Date), _ 
    Month(PreviousMonth), 1) 
End Function 
Function dhLastDayInMonth(Optional dtmDate As Date = 0) As Date 
    ' Return the last day in the specified month. 
    PreviousMonth = DateAdd("m", -1, Date) 
    dhLastDayInMonth = DateSerial(Year(Date), _ 
    Month(PreviousMonth) + 1, 0) 
End Function 
관련 문제