¾Æ·¡¿¡ ÀûÀ» ½ºÅ©¸³Æ®´Â °ø±¸ Àç°í °ü¸® ½Ã½ºÅÛ Àε¥ ¼öÁ¤ÀÌ ÇÊ¿äÇØ. ù¹ø° À¯ÀúÆû ½ºÅ©¸³Æ® Private Sub UserForm_Initialize() ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå Dim wsData As Worksheet Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®") ' Á¾·ù ·Îµå cboType.Clear Dim rngType As Range

[´ñ±Û¼ö (18)]
rank ´ç±ÙÆDZ٠2024-06-28 (±Ý) 11:24 Á¶È¸ : 174 Ãßõ : 6  Ãßõ  ½Å°í
rank ´ç±ÙÆDZÙ
¾Æ·¡¿¡ ÀûÀ» ½ºÅ©¸³Æ®´Â °ø±¸ Àç°í °ü¸® ½Ã½ºÅÛ Àε¥ ¼öÁ¤ÀÌ ÇÊ¿äÇØ. ù¹ø° À¯ÀúÆû ½ºÅ©¸³Æ® Private Sub UserForm_Initialize() ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå Dim wsData As Worksheet Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®") ' Á¾·ù ·Îµå cboType.Clear Dim rngType As Range
rank AIê

ÇØ´ç ¿ä±¸»çÇ×À» ¹Ý¿µÇÏ¿© Äڵ带 ¼öÁ¤ÇØ µå¸± ÀÖ½À´Ï´Ù. ¾Æ·¡¿Í °°ÀÌ °¢ ½ºÅ©¸³Æ®¸¦ ¾÷µ¥ÀÌÆ® ÇØÁÖ¼¼¿ä.

ù ¹ø° À¯ÀúÆû ½ºÅ©¸³Æ® (³¯Â¥ Ãß°¡ ¹× Á¾·ù-Ç°¸í ÀÇÁ¸¼º Ãß°¡):

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Date ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù. ¶Ç´Â ÇÊ¿äÇÑ °æ¿ì "³¯Â¥ ¼±ÅÃ" ¶óº§À» »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' ³¯Â¥ ¼±ÅÃÀ» À§ÇÑ Ä¶¸°´õ È£Ãâ
    Dim calendarForm As Object
    Set calendarForm = CreateObject("MSComCtl2.MonthView.2")  ' MSCOMCT2.OCX ÄÄÆ÷³ÍÆ® ÇÊ¿ä (µî·Ï Çʼö)
    
    With calendarForm
        .MaxDate = Date
        .Show
        txtDate.Value = calendarForm.Value
    End With
End Sub

µÎ ¹ø°´Â 1¹ø ¸ðµâ (³¯Â¥ Çʵå Ãß°¡):

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As Date, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "ÀÔ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:B" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim found As Range
    Set found = rg.Find(Ç°¸í)
    If Not found Is Nothing Then
        found.Offset(, 2).Value = found.Offset(, 2).Value + ¼ö·®
    Else
        Dim NewRow As Long
        NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
        ws1.Cells(NewRow, 1).Value = Á¾·ù
        ws1.Cells(NewRow, 2).Value = Ç°¸í
        ws1.Cells(NewRow, 3).Value = ¼ö·®
    End If

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As Date, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "Ãâ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:B" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim found As Range
    Set found = rg.Find(Ç°¸í)
    If Not found Is Nothing Then
        found.Offset(, 2).Value = found.Offset(, 2).Value - ¼ö·®
    Else
        MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù."
    End If

    UserForm1.Hide
End Sub

¼¼ ¹ø°´Â 2¹ø ¸ðµâ (»ç¿ëÀÚ Æû ÃʱâÈ­ ¹× ³¯Â¥ Çʵå Ãß°¡):

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

À§ÀÇ Äڵ忡¼­´Â À¯ÀúÆû¿¡ ³¯Â¥ Çʵå(txtDate)¸¦ Ãß°¡ÇÏ°í, Á¾·ù¿Í Ç°¸í °£ÀÇ ÀÇÁ¸¼ºÀ» ¼³Á¤ÇÏ¿´½À´Ï´Ù. ¶ÇÇÑ ³¯Â¥ ¼±ÅÃÀ» À§ÇÑ Ä¶¸°´õ ÆûÀ» Ãß°¡ÇÏ¿´À¸´Ï ÇÊ¿ä¿¡ µû¶ó MSCOMCTL.OCX ÆÄÀÏÀ» ÀûÀýÈ÷ µî·ÏÇØ¾ß ÇÕ´Ï´Ù.

´ñ±Û 18°³
´ñ±Û¾²±â
´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 11:35
txtDate´Â ¾î¶² ŸÀÔÀ¸·Î ¾îµð¿¡ Ãß°¡ÇØ¾ß Çϴ°žß? lblDateµµ Ãß°¡ÇØ¾ß ÇÑ´Ù¸é ¾î¶»°Ô ¾îµð¿¡ Ãß°¡ÇØ¾ß ÇÏÁö? ±×¸®°í 'ÇÊ¿ä¿¡ µû¶ó MSCOMCTL.OCX ÆÄÀÏÀ» ÀûÀýÈ÷ µî·ÏÇØ¾ß ÇÕ´Ï´Ù.'¶ó´Â°Ô ¹«½¼¸»ÀÎÁö ¸ð¸£°Ú¾î.
     
       
AIê 2024-06-28 (±Ý) 11:35
@´ç±ÙÆDZÙ

txtDate¿Í lblDate´Â »ç¿ëÀÚ Æû(UserForm)¿¡ Ãß°¡ÇÏ´Â ÄÁÆ®·ÑÀÔ´Ï´Ù. À̸¦ ÅëÇØ ³¯Â¥ ÀÔ·Â Çʵå¿Í ±×¿¡ ´ëÇÑ ¶óº§À» Á¦°øÇÏ°Ô µË´Ï´Ù.

³¯Â¥ ÇÊµå ¹× ¶óº§ Ãß°¡ ¹æ¹ý

  1. À¯ÀúÆû µðÀÚÀÎ

    • Excel VBA ÆíÁý±â(Alt + F11)¿¡¼­ UserForm1À» ¿±´Ï´Ù.
    • µµ±¸ »óÀÚ¿¡¼­ TextBox¸¦ ¼±ÅÃÇÏ°í Æû¿¡ Ãß°¡ÇÕ´Ï´Ù. À̸§À» txtDate·Î ¼³Á¤ÇÕ´Ï´Ù.
    • µµ±¸ »óÀÚ¿¡¼­ LabelÀ» ¼±ÅÃÇÏ°í ÅؽºÆ®¹Ú½º ±Ùó¿¡ Ãß°¡ÇÕ´Ï´Ù. À̸§À» lblDate·Î ¼³Á¤ÇÕ´Ï´Ù.
    • lblDateÀÇ Caption ¼Ó¼ºÀ» "³¯Â¥"·Î ¼³Á¤ÇÕ´Ï´Ù.
  2. ÅؽºÆ®¹Ú½º¿Í ¶óº§ À§Ä¡ ¹× Å©±â ¼³Á¤

    • UserForm1À» ¿­¾î txtDate¿Í lblDateÀÇ À§Ä¡¸¦ ÀûÀýÈ÷ Á¶Á¤ÇÕ´Ï´Ù.

UserFormÀÇ ÃʱâÈ­ Äڵ忡 ³¯Â¥ Çʵå¿Í ¶óº§À» Ãß°¡ÇÏ´Â ºÎºÐ (¼öÁ¤µÈ UserForm_Initialize):

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Date ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù.
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' ³¯Â¥ ¼±ÅÃÀ» À§ÇÑ Ä¶¸°´õ È£Ãâ
    Dim calendarForm As Object
    Set calendarForm = CreateObject("MSComCtl2.MonthView.2")  ' MSCOMCTL.OCX ÄÄÆ÷³ÍÆ® ÇÊ¿ä (µî·Ï Çʼö)
    
    With calendarForm
        .MaxDate = Date
        .Show
        txtDate.Value = calendarForm.Value
    End With
End Sub

MSCOMCTL.OCX ÆÄÀÏ

mscomctl.ocx´Â MicrosoftÀÇ ÄÁÆ®·Ñ ÆÄÀÏ·Î, ´Ù¾çÇÑ Windows API ÄÁÆ®·ÑÀ» Á¦°øÇÕ´Ï´Ù. À̸¦ »ç¿ëÇÏ¿© Ķ¸°´õ¸¦ Æ÷ÇÔÇÑ ´Ù¾çÇÑ ÄÁÆ®·ÑÀ» »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.

ÆÄÀÏ µî·Ï ¹æ¹ý:

  1. mscomctl.ocx ÆÄÀÏ ´Ù¿î·Îµå: ÀÎÅͳݿ¡¼­ mscomctl.ocx ÆÄÀÏÀ» ´Ù¿î·ÎµåÇϼ¼¿ä.
  2. ÆÄÀÏ À̵¿: ´Ù¿î·ÎµåÇÑ ÆÄÀÏÀ» C:\Windows\System32 Æú´õ¿¡ º¹»çÇÕ´Ï´Ù.
  3. ¸í·É ÇÁ·ÒÇÁÆ®¿¡¼­ µî·Ï:
    • ¸í·É ÇÁ·ÒÇÁÆ®(cmd)¸¦ °ü¸®ÀÚ ±ÇÇÑÀ¸·Î ½ÇÇàÇÕ´Ï´Ù.
    • ´ÙÀ½ ¸í·É¾î¸¦ ÀÔ·ÂÇÏ¿© µî·ÏÇÕ´Ï´Ù.
      regsvr32 C:\Windows\System32\mscomctl.ocx
      

ÀÌÁ¦ Ãß°¡ÇÑ txtDate¿Í lblDate°¡ Á¤È®È÷ µ¿ÀÛÇϸç, Ķ¸°´õ¸¦ ÅëÇØ ³¯Â¥¸¦ ÀÔ·ÂÇÒ ¼ö ÀÖ½À´Ï´Ù. À̸¦ ÅëÇØ ³¯Â¥, Á¾·ù ¹× Ç°¸íÀ» ¼±ÅÃÇÒ ¼ö ÀÖ´Â À¯ÀúÆûÀ» ¿Ï¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù.

´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 11:43
À¯ÀúÆû, ¸ðµâ1, ¸ðµâ2 µû·Î ´Ù½ÃÇѹø Äڵ带 Àüü ¾Ë·ÁÁÙ·¡?
     
       
AIê 2024-06-28 (±Ý) 11:43
@´ç±ÙÆDZÙ

¹°·ÐÀÔ´Ï´Ù. À¯ÀúÆû, ¸ðµâ1, ¸ðµâ2¸¦ °¢°¢ Àüü ÄÚµå·Î Á¦°øÇØ µå¸®°Ú½À´Ï´Ù.

À¯ÀúÆû (UserForm) ÄÚµå

¾Æ·¡ Äڵ带 UserForm1ÀÇ ÄÚµå â¿¡ »ðÀÔÇϼ¼¿ä:

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Date ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù.
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' ³¯Â¥ ¼±ÅÃÀ» À§ÇÑ Ä¶¸°´õ È£Ãâ
    Dim calendarForm As Object
    Set calendarForm = CreateObject("MSComCtl2.MonthView.2")  ' MSCOMCTL.OCX ÄÄÆ÷³ÍÆ® ÇÊ¿ä (µî·Ï Çʼö)
    
    With calendarForm
        .MaxDate = Date
        .Show
        txtDate.Value = calendarForm.Value
    End With
End Sub

¸ðµâ1 ÄÚµå

¾Æ·¡ Äڵ带 Module1¿¡ »ðÀÔÇϼ¼¿ä:

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As Date, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "ÀÔ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:B" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim found As Range
    Set found = rg.Find(Ç°¸í)
    If Not found Is Nothing Then
        found.Offset(, 2).Value = found.Offset(, 2).Value + ¼ö·®
    Else
        Dim NewRow As Long
        NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
        ws1.Cells(NewRow, 1).Value = Á¾·ù
        ws1.Cells(NewRow, 2).Value = Ç°¸í
        ws1.Cells(NewRow, 3).Value = ¼ö·®
    End If

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As Date, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "Ãâ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:B" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim found As Range
    Set found = rg.Find(Ç°¸í)
    If Not found Is Nothing Then
        found.Offset(, 2).Value = found.Offset(, 2).Value - ¼ö·®
    Else
        MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù."
    End If

    UserForm1.Hide
End Sub

¸ðµâ2 ÄÚµå

¾Æ·¡ Äڵ带 Module2¿¡ »ðÀÔÇϼ¼¿ä:

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

À§ÀÇ Äڵ忡¼­ lblDate´Â ¶óº§ ÄÁÆ®·Ñ·Î, À¯ÀúÆûÀÇ µðÀÚÀÎ º¸±â ¸ðµå¿¡¼­ Ãß°¡ÇÒ ¼ö ÀÖ½À´Ï´Ù. txtDate´Â ÅؽºÆ®¹Ú½º ÄÁÆ®·ÑÀÔ´Ï´Ù. µÎ ÄÁÆ®·ÑÀº °¢°¢ Æû¿¡ Ãß°¡ÇÏ°í ÀûÀýÇÑ À§Ä¡·Î ¹èÄ¡Çϼ¼¿ä.

MSCOMCTL.OCX ÆÄÀÏ

MSCOMCTL.OCX ÆÄÀÏ µî·Ï ¹®Á¦¿¡ ´ëÇÑ ´Ü°è´Â ´ÙÀ½°ú °°½À´Ï´Ù:

  1. mscomctl.ocx ÆÄÀÏ ´Ù¿î·Îµå: ÀÎÅͳݿ¡¼­ ÇØ´ç ÆÄÀÏÀ» °Ë»öÇÏ¿© ´Ù¿î·ÎµåÇϼ¼¿ä.
  2. ÆÄÀÏ À̵¿: ´Ù¿î·ÎµåÇÑ ÆÄÀÏÀ» C:\Windows\System32 Æú´õ¿¡ º¹»çÇÕ´Ï´Ù.
  3. ¸í·É ÇÁ·ÒÇÁÆ®¿¡¼­ µî·Ï:
    • ¸í·É ÇÁ·ÒÇÁÆ®(cmd)¸¦ °ü¸®ÀÚ ±ÇÇÑÀ¸·Î ½ÇÇàÇÕ´Ï´Ù.
    • ´ÙÀ½ ¸í·É¾î¸¦ ÀÔ·ÂÇÏ¿© µî·ÏÇÕ´Ï´Ù:
      regsvr32 C:\Windows\System32\mscomctl.ocx
      

ÀÌ µî·Ï ÀýÂ÷´Â ³¯Â¥ ¼±Åà Ķ¸°´õ ÄÁÆ®·ÑÀ» ¿Ã¹Ù¸£°Ô »ç¿ëÇϱâ À§ÇØ ÇÊ¿äÇÕ´Ï´Ù. Excel¿¡¼­ COM ÄÁÆ®·Ñ ¶óÀ̺귯¸®¸¦ È°¿ëÇÏ·Á¸é À§ÀÇ ÀýÂ÷¸¦ µû¸£¼¼¿ä. ±×·¸Áö ¾ÊÀ¸¸é ´Ù¸¥ ÇüÅÂÀÇ ³¯Â¥ ÀÔ·Â ¹æ½ÄÀ» °í·ÁÇغ¸¼Å¾ß ÇÕ´Ï´Ù(¿¹: DatePicker ÄÁÆ®·Ñ »ç¿ë).

´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 11:53
½ÃÀÛºÎÅÍ ¿À·ù°¡ ³ª´Âµ¥? rivate Sub UserForm_Initialize() ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå Dim wsData As Worksheet Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®") À§¿¡¼­ sub¿¡¼­ ÄÄÆÄÀÏ ¿À·ù¶ó°í ÇÏ°í ÇÊ¿äÇÑ ¿ä¼Ò´Â '½Ä' À̶ó³×.
     
       
AIê 2024-06-28 (±Ý) 11:53
@´ç±ÙÆDZÙ

ÄÄÆÄÀÏ ¿À·ù°¡ ¹ß»ýÇÏ´Â ÀÌÀ¯´Â ´ë°³ ŸÀÌÇÎ ½Ç¼ö³ª À߸øµÈ ±¸¹® ¶§¹®ÀÔ´Ï´Ù. ÁÖ¾îÁø ÄÚµåÀÇ Ã¹ ¶óÀο¡¼­ Private Å°¿öµå°¡ À߸ø ŸÀÌÇÎµÈ °Í °°½À´Ï´Ù. "rivate" ´ë½Å "Private"·Î ¼öÁ¤ÇϽñ⠹ٶø´Ï´Ù.

¾Æ·¡¿¡¼­ ¿À·ù ¾ø´Â ¹æ½ÄÀ¸·Î ´Ù½Ã ¼³¸íÇÏ°Ú½À´Ï´Ù.

À¯ÀúÆû (UserForm) ÄÚµå

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Date ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù.
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' ³¯Â¥ ¼±ÅÃÀ» À§ÇÑ Ä¶¸°´õ È£Ãâ
    Dim calendarForm As Object
    Set calendarForm = CreateObject("MSComCtl2.MonthView.2")  ' MSCOMCTL.OCX ÄÄÆ÷³ÍÆ® ÇÊ¿ä (µî·Ï Çʼö)
    
    With calendarForm
        .MaxDate = Date
        .Show
        txtDate.Value = calendarForm.Value
    End With
End Sub

¸ðµâ1 ÄÚµå

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As Date, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "ÀÔ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:B" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim found As Range
    Set found = rg.Find(Ç°¸í)
    If Not found Is Nothing Then
        found.Offset(, 2).Value = found.Offset(, 2).Value + ¼ö·®
    Else
        Dim NewRow As Long
        NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
        ws1.Cells(NewRow, 1).Value = Á¾·ù
        ws1.Cells(NewRow, 2).Value = Ç°¸í
        ws1.Cells(NewRow, 3).Value = ¼ö·®
    End If

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As Date, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "Ãâ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:B" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim found As Range
    Set found = rg.Find(Ç°¸í)
    If Not found Is Nothing Then
        found.Offset(, 2).Value = found.Offset(, 2).Value - ¼ö·®
    Else
        MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù."
    End If

    UserForm1.Hide
End Sub

¸ðµâ2 ÄÚµå

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

ÅؽºÆ®¹Ú½º¿Í ¶óº§ Ãß°¡ ¹æ¹ý

  1. À¯ÀúÆû µðÀÚÀÎ

    • Excel VBA ÆíÁý±â(Alt + F11)¿¡¼­ UserForm1À» ¿±´Ï´Ù.
    • µµ±¸ »óÀÚ¿¡¼­ TextBox¸¦ ¼±ÅÃÇÏ°í, À¯ÀúÆû¿¡ Ãß°¡ÇÕ´Ï´Ù. À̸§À» txtDate·Î ¼³Á¤ÇÕ´Ï´Ù.
    • µµ±¸ »óÀÚ¿¡¼­ Label¸¦ ¼±ÅÃÇÏ°í, À¯ÀúÆû¿¡ Ãß°¡ÇÕ´Ï´Ù. À̸§À» lblDate·Î ¼³Á¤ÇÕ´Ï´Ù. ¶óº§ÀÇ Caption ¼Ó¼ºÀ» "³¯Â¥"·Î ¼³Á¤ÇÕ´Ï´Ù.
  2. ÅؽºÆ®¹Ú½º¿Í ¶óº§ À§Ä¡¿Í Å©±â ¼³Á¤

    • UserForm1À» ¿­¾î txtDate¿Í lblDateÀÇ À§Ä¡¸¦ ÀûÀýÈ÷ Á¶Á¤ÇÕ´Ï´Ù.
  3. MSCOMCTL.OCX ÆÄÀÏ µî·Ï ¹æ¹ý

    • ÀÎÅͳÝÀ» ÅëÇØ mscomctl.ocx ÆÄÀÏÀ» ´Ù¿î·ÎµåÇÕ´Ï´Ù.
    • ´Ù¿î·ÎµåÇÑ ÆÄÀÏÀ» C:\Windows\System32 Æú´õ¿¡ º¹»çÇÕ´Ï´Ù.
    • ¸í·É ÇÁ·ÒÇÁÆ®(cmd)¸¦ °ü¸®ÀÚ ±ÇÇÑÀ¸·Î ½ÇÇàÇÕ´Ï´Ù.
    • ¸í·É ÇÁ·ÒÇÁÆ®¿¡¼­ ´ÙÀ½ ¸í·É¾î¸¦ ÀÔ·ÂÇÏ¿© ÆÄÀÏÀ» µî·ÏÇÕ´Ï´Ù.
      regsvr32 C:\Windows\System32\mscomctl.ocx
      

À̸¦ ÅëÇØ ÇÊ¿äÇÑ ¸ðµç ¼öÁ¤°ú Ãß°¡¸¦ ¿Ï·áÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌÁ¦ À¯ÀúÆûÀ» ¿­°í ³¯Â¥ Çʵ带 »ç¿ëÇÏ¿© ³¯Â¥¸¦ ¼±ÅÃÇÒ ¼ö ÀÖÀ¸¸ç, ¼±ÅÃµÈ ³¯Â¥¿Í ´Ù¸¥ ÀÔ·Â Çʵ带 ÅëÇØ ÀÔÃâ°í ±â·ÏÀ» Ãß°¡ÇÒ ¼ö ÀÖ½À´Ï´Ù.

´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 12:19
¹®Á¦°¡ ÀÖ¾î. ÀÔ°íÇÒ¶§ ´ã´çÀÚ¸¦ ³Ö´Â ÀÌÀ¯´Â ÀÔÃâ°í ±â·Ï ½ÃÆ®¿¡ Á¤º¸¸¦ ³²±â±â À§ÇÔ»ÓÀ̾ß. ±×·¯´Ï ù¹ø° ½ÃÆ®ÀÎ Àç°í ¸®½ºÆ®¿¡ ÀÔ°í µÇ°í Ãâ°íµÇ´Â ¼ö·®µéÀº ´ã´çÀÚ¿Í »ó°ü¾øÀÌ Á¾·ù¿Í Ç°¸íÀÌ ¸ÂÀ¸¸é ¼ö·®ÀÌ º¯°æµÇ¾î¾ß Çϴ°ÅÁö. ±×¸®°í ³¯Â¥¸¦ ³ÖÀ» ÅؽºÆ®¹Ú½º(txtDate)¸¦ Ŭ¸¯Çϸé Áöµµ°¡ ³ª¿ÀÁö ¾Ê°í ¾Æ·¡¿Í °°ÀÌ ¿¡·¯°¡ ³ª. '35771'·±Å¸ÀÓ ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. Max Date ¼Ó¼º¿¡ ´ëÇØ À߸øµÈ ³¯Â¥¸¦ ÁöÁ¤ÇÏ¿´½À´Ï´Ù. ÀÌ°Ç ¿Ö ±×·²±î?
     
       
AIê 2024-06-28 (±Ý) 12:19
@´ç±ÙÆDZÙ

Áöµµ¸¦ »ç¿ëÇÏ¿© ³¯Â¥¸¦ ¼±ÅÃÇÏ´Â ±â´ÉÀÌ Á¦´ë·Î ±¸ÇöµÇÁö ¾ÊÀ» MSComCtl2.MonthView ÄÁÆ®·Ñ ´ë½Å Microsoft Date and Time Picker Control (DatePicker ÄÁÆ®·Ñ)¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ´õ ³ªÀ» ¼ö ÀÖ½À´Ï´Ù. À̸¦ ÅëÇØ ´õ Á÷°üÀûÀÎ ³¯Â¥ ¼±Åà ±â´ÉÀ» Á¦°øÇÒ ¼ö ÀÖ½À´Ï´Ù. ±×·¯³ª ¸ðµç Excel ¼³Ä¡¿¡¼­ ÀÌ ÄÁÆ®·ÑÀÌ Áö¿øµÇ´Â °ÍÀº ¾Æ´Õ´Ï´Ù.

¿ì¼±, ³¯Â¥ ¼±Åà ¿¡·¯ÀÇ ¹®Á¦¸¦ ÇØ°áÇÏ°í, »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ ³¯Â¥¸¦ ÅؽºÆ® ¹Ú½º·Î °¡Á®¿Àµµ·Ï ¼öÁ¤ÇØ º¸°Ú½À´Ï´Ù. ³¯Â¥ ¿¡·¯¸¦ ÇØ°áÇϱâ À§ÇØ ÅؽºÆ®¹Ú½º¸¦ Ŭ¸¯ ½Ã Calendar ControlÀ» »ç¿ëÇÏÁö ¾Ê°í ƯÁ¤ ³¯Â¥ Çü½ÄÀ» Á÷Á¢ ÀÔ·ÂÇÏ°Ô ÇÒ ¼ö ÀÖ½À´Ï´Ù.

±× ´ÙÀ½À¸·Î, ÀÔ°í ¹× Ãâ°í ½Ã ´ã´çÀÚ°¡ ¾Æ´Ñ Á¾·ù¿Í Ç°¸í¿¡ µû¶ó ¼ö·®À» °»½ÅÇÏ´Â ºÎºÐÀ» ¼öÁ¤ÇÏ°Ú½À´Ï´Ù.

À¯ÀúÆû (UserForm) ÄÚµå

¾Æ·¡ Äڵ带 UserForm1ÀÇ ÄÚµå â¿¡ »ðÀÔÇϼ¼¿ä:

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Date ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù.
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' TXTDate Ŭ¸¯ ½Ã ³¯Â¥ ¼±ÅÃ¿ë ±âº» ÀÔ·ÂÇü½ÄÀ¸·Î Àüȯ
    txtDate.Value = InputBox("³¯Â¥¸¦ yyyy-mm-dd Çü½ÄÀ¸·Î ÀÔ·ÂÇϼ¼¿ä.", "³¯Â¥ ÀÔ·Â", txtDate.Value)
End Sub

¸ðµâ1 ÄÚµå

¾Æ·¡ Äڵ带 Module1¿¡ »ðÀÔÇϼ¼¿ä:

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As Date, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "ÀÔ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:B" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim found As Range
    Set found = rg.Find(What:=Ç°¸í, LookIn:=xlValues, LookAt:=xlWhole)

    If Not found Is Nothing Then
        found.Offset(, 2).Value = found.Offset(, 2).Value + ¼ö·®
    Else
        Dim NewRow As Long
        NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
        ws1.Cells(NewRow, 1).Value = Á¾·ù
        ws1.Cells(NewRow, 2).Value = Ç°¸í
        ws1.Cells(NewRow, 3).Value = ¼ö·®
    End If

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As Date, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "Ãâ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:B" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim found As Range
    Set found = rg.Find(What:=Ç°¸í, LookIn:=xlValues, LookAt:=xlWhole)

    If Not found Is Nothing Then
        found.Offset(, 2).Value = found.Offset(, 2).Value - ¼ö·®
    Else
        MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù."
    End If

    UserForm1.Hide
End Sub

¸ðµâ2 ÄÚµå

¾Æ·¡ Äڵ带 Module2¿¡ »ðÀÔÇϼ¼¿ä:

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End

À§ÀÇ °íħÀ¸·Î ´ÙÀ½°ú °°Àº º¯°æ »çÇ×ÀÌ Àû¿ëµË´Ï´Ù:

  1. txtDate ÅؽºÆ®¹Ú½º¸¦ Ŭ¸¯ÇÏ¸é ³¯Â¥ Çü½Ä yyyy-mm-ddÀ» ÀÔ·ÂÇϵµ·Ï ÇÁ·ÒÇÁÆ®°¡ ³ªÅ¸³³´Ï´Ù.
  2. ÀÔ°í ¹× Ãâ°í ½Ã Responsible Çʵå´Â ·¹Äڵ忡 ÀúÀåµÇÁö¸¸, Àç°í ¾÷µ¥ÀÌÆ®´Â Á¾·ù¿Í Ç°¸í¿¡ µû¶ó ÀÌ·ç¾îÁý´Ï´Ù.
  3. »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ ³¯Â¥´Â Àç°í ·¹Äڵ忡 Ãß°¡µË´Ï´Ù.

ÀÌ¿Í °°Àº ¼³Á¤À» ÅëÇØ ±âÁ¸ ¹®Á¦¸¦ ÇØ°áÇÏ°í À¯ÀúÆûÀÌ Á¤È®È÷ ÀÛµ¿ÇÒ ¼ö ÀÖµµ·Ï ÇÕ´Ï´Ù.

´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 12:27
ÀÔ°í½Ã´Â ù¹ø° ½ÃÆ®ÀÎ Àç°í¸®½ºÆ®¿¡ Á¾·ù¿Í Ç°¸ñÀÌ °°Àº ¹°Ç°µéÀÇ ¼ö·®ÀÌ ¿Ã¶ó°¡°í Ãâ°í½Ã´Â ÁÙ¾îµé¾î¾ß Çϴµ¥ ±×°Ô ¹Ý¿µÀÌ ¾ÈµÇ´Â °Í °°¾Æ. ±×¸®°í ³¯Â¥ ÀÔ·ÂÄ­ÀÌ ¶ß´Â°Ç ÁÁÀºµ¥ 06.05.24 ÀÌ·± Çü½ÄÀ¸·Î ¹Ù²Ü¼ö´Â ¾ø´Â°Ç°¡?
     
       
AIê 2024-06-28 (±Ý) 12:27
@´ç±ÙÆDZÙ

ÀÔ°í ½Ã¿Í Ãâ°í ½Ã, ù ¹ø° ½ÃÆ®ÀÎ "Àç°í ¸®½ºÆ®"¿¡¼­ Á¾·ù¿Í Ç°¸ñÀÌ °°Àº ¹°Ç°µéÀÇ ¼ö·®ÀÌ Á¤È®È÷ º¯°æµÇµµ·Ï Äڵ带 ¼öÁ¤ÇÏ°Ú½À´Ï´Ù. ¶ÇÇÑ ³¯Â¥ Çü½ÄÀ» ¿øÇÏ´Â ´ë·Î (yyyy.mm.dd) ¼³Á¤Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù.

À¯ÀúÆû (UserForm) ÄÚµå

¾Æ·¡ Äڵ带 UserForm1ÀÇ ÄÚµå â¿¡ »ðÀÔÇϼ¼¿ä:

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Format(Date, "yyyy.mm.dd") ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù (Çü½Ä: yyyy.mm.dd).
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' TXTDate Ŭ¸¯ ½Ã ³¯Â¥ ¼±ÅÃ¿ë ±âº» ÀÔ·ÂÇü½ÄÀ¸·Î Àüȯ
    txtDate.Value = Format(InputBox("³¯Â¥¸¦ yyyy.mm.dd Çü½ÄÀ¸·Î ÀÔ·ÂÇϼ¼¿ä.", "³¯Â¥ ÀÔ·Â", txtDate.Value), "yyyy.mm.dd")
End Sub

¸ðµâ1 ÄÚµå

¾Æ·¡ Äڵ带 Module1¿¡ »ðÀÔÇϼ¼¿ä:

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "ÀÔ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·®
            UserForm1.Hide
            Exit Sub
        End If
    Next cell

    ' Á¾·ù¿Í Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾øÀ» °æ¿ì Ãß°¡
    Dim NewRow As Long
    NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
    ws1.Cells(NewRow, 1).Value = Á¾·ù
    ws1.Cells(NewRow, 2).Value = Ç°¸í
    ws1.Cells(NewRow, 3).Value = ¼ö·®

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' Ãâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "Ãâ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            cell.Offset(, 2).Value = cell.Offset(, 2).Value - ¼ö·®
            If cell.Offset(, 2).Value <  Then
                MsgBox "Àç°í ¼ö·®ÀÌ ºÎÁ·ÇÕ´Ï´Ù.", vbCritical
                cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·®
            End If
            UserForm1.Hide
            Exit Sub
        End If
    Next cell

    MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù.", vbExclamation
    UserForm1.Hide
End Sub

¸ðµâ2 ÄÚµå

¾Æ·¡ Äڵ带 Module2¿¡ »ðÀÔÇϼ¼¿ä:

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End

Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

À§ÀÇ Äڵ忡¼­ À¯ÀúÆûÀÇ txtDate Çʵ带 Ŭ¸¯ÇÏ¸é ³¯Â¥ ÀÔ·ÂÀ» ¹Þµµ·Ï ÇÏ¿´½À´Ï´Ù. ¶ÇÇÑ ÀÔ°í¿Í Ãâ°í ½Ã "Àç°í ¸®½ºÆ®"¿¡¼­ Á¾·ù¿Í Ç°¸í¿¡ ¸Â´Â ¸ðµç Ç׸ñÀÇ ¼ö·®À» º¯°æÇϵµ·Ï ¼öÁ¤ÇÏ¿´½À´Ï´Ù. ³¯Â¥ Çü½Äµµ yyyy.mm.dd·Î ¼öÁ¤µÇ¾ú½À´Ï´Ù. ÀÌÁ¦ »ç¿ëÀÚ ÀÎÅÍÆäÀ̽º¿Í ±â´ÉÀÌ °³¼±µÉ °ÍÀÔ´Ï´Ù.

´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 13:35
³¯Â¥Çü½ÄÀ» . ¾øÀÌ 6ÀÚ¸®·Î ÇÏ°í ½Í¾î¿ä.
     
       
AIê 2024-06-28 (±Ý) 13:35
@´ç±ÙÆDZÙ

³¯Â¥ Çü½ÄÀ» 6ÀÚ¸®·Î º¯°æÇϱâ À§Çؼ­´Â yyyy.mm.dd Çü½Ä ´ë½Å ydd` Çü½ÄÀ» »ç¿ëÇÏ¸é µË´Ï´Ù. ¾Æ·¡´Â ³¯Â¥ Çü½ÄÀ» º¯°æÇÑ ¼öÁ¤µÈ ÄÚµåÀÔ´Ï´Ù.

À¯ÀúÆû (UserForm) ÄÚµå

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Format(Date, "yymmdd") ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù (Çü½Ä: yymmdd).
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' TXTDate Ŭ¸¯ ½Ã ³¯Â¥ ¼±ÅÃ¿ë ±âº» ÀÔ·ÂÇü½ÄÀ¸·Î Àüȯ
    txtDate.Value = Format(InputBox("³¯Â¥¸¦ yymmdd Çü½ÄÀ¸·Î ÀÔ·ÂÇϼ¼¿ä.", "³¯Â¥ ÀÔ·Â", txtDate.Value), "yymmdd")
End Sub

¸ðµâ1 ÄÚµå

¾Æ·¡ Äڵ带 Module1¿¡ »ðÀÔÇϼ¼¿ä:

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "ÀÔ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·®
            UserForm1.Hide
            Exit Sub
        End If
    Next cell

    ' Á¾·ù¿Í Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾øÀ» °æ¿ì Ãß°¡
    Dim NewRow As Long
    NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
    ws1.Cells(NewRow, 1).Value = Á¾·ù
    ws1.Cells(NewRow, 2).Value = Ç°¸í
    ws1.Cells(NewRow, 3).Value = ¼ö·®

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' Ãâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "Ãâ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            cell.Offset(, 2).Value = cell.Offset(, 2).Value - ¼ö·®
            If cell.Offset(, 2).Value <  Then
                MsgBox "Àç°í ¼ö·®ÀÌ ºÎÁ·ÇÕ´Ï´Ù.", vbCritical
                cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·®
            End If
            UserForm1.Hide
            Exit Sub
        End If
    Next cell

    MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù.", vbExclamation
    UserForm1.Hide
End Sub

¸ðµâ2 ÄÚµå

¾Æ·¡ Äڵ带 Module2¿¡ »ðÀÔÇϼ¼¿ä:

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
EndSub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

À§ÀÇ Äڵ忡¼­ À¯ÀúÆûÀÇ txtDate Çʵ带 Ŭ¸¯ÇÏ¸é ³¯Â¥ ÀÔ·ÂÀ» ¹Þµµ·Ï ÇÏ¿´½À´Ï´Ù. ¶ÇÇÑ ÀÔ°í¿Í Ãâ°í ½Ã "Àç°í ¸®½ºÆ®"¿¡¼­ Á¾·ù¿Í Ç°¸í¿¡ ¸Â´Â ¸ðµç Ç׸ñÀÇ ¼ö·®À» º¯°æÇϵµ·Ï ¼öÁ¤ÇÏ¿´½À´Ï´Ù. ³¯Â¥ Çü½Äµµ yymmdd·Î ¼öÁ¤µÇ¾ú½À´Ï´Ù. ÀÌÁ¦ »ç¿ëÀÚ ÀÎÅÍÆäÀ̽º¿Í ±â´ÉÀÌ °³¼±µÉ °ÍÀÔ´Ï´Ù.

´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 13:38
¸ðµâ2¿¡¼­ ¿¡·¯³ª³×¿ä.
     
       
AIê 2024-06-28 (±Ý) 13:38
@´ç±ÙÆDZÙ

¸ðµâ2¿¡¼­ ¿¡·¯°¡ ³ª´Â ÀÌÀ¯´Â ¾Æ¸¶ Á¾·áµÇÁö ¾Ê´Â Sub ¶óÀÎÀÌ Æ÷ÇԵǾú±â ¶§¹®ÀÏ °¡´É¼ºÀÌ Å®´Ï´Ù. ¸ðµâ2 Äڵ带 ¾Æ·¡¿Í °°ÀÌ ´Ù½Ã Á¤¸®ÇØ º¸°Ú½À´Ï´Ù.

¸ðµâ2 ÄÚµå

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With


Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub```

À¯ÀúÆû â¿¡¼­ ÀÔ·Â Çʵ带 ÃʱâÈ­ÇÏ°í, ÀÔ°í ¹× Ãâ°í âÀ» ¿Ã¹Ù¸£°Ô º¸¿©ÁÖ±â À§ÇÑ ÄÚµåÀÔ´Ï´Ù. À§ Äڵ带 º¹»çÇÏ¿© ¸ðµâ2¿¡ ºÙ¿©³ÖÀ¸¼¼¿ä.

´Ù½Ã ÇÑ ¹ø Á¤¸®ÇÏ¿© À¯ÀúÆû(UserForm), ¸ðµâ1(Module1), ±×¸®°í ¸ðµâ2(Module2)À» ¸íÈ®ÇÏ°Ô Á¦°øÇÕ´Ï´Ù.

## À¯ÀúÆû (UserForm) ÄÚµå

```vba
Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Format(Date, "yymmdd") ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù (Çü½Ä: yymmdd).
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' TXTDate Ŭ¸¯ ½Ã ³¯Â¥ ¼±ÅÃ¿ë ±âº» ÀÔ·ÂÇü½ÄÀ¸·Î Àüȯ
    txtDate.Value = Format(InputBox("³¯Â¥¸¦ yymmdd Çü½ÄÀ¸·Î ÀÔ·ÂÇϼ¼¿ä.", "³¯Â¥ ÀÔ·Â", txtDate.Value), "yymmdd")
End Sub

¸ðµâ1 ÄÚµå

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "ÀÔ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·®
            UserForm1.Hide
            Exit Sub
        End If
    Next cell

    ' Á¾·ù¿Í Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾øÀ» °æ¿ì Ãß°¡
    Dim NewRow As Long
    NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
    ws1.Cells(NewRow, 1).Value = Á¾·ù
    ws1.Cells(NewRow, 2).Value = Ç°¸í
    ws1.Cells(NewRow, 3).Value = ¼ö·®

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' Ãâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "Ãâ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            cell.Offset(, 2).Value = cell.Offset(, 2).Value - ¼ö·®
            If cell.Offset(, 2).Value <  Then
                MsgBox "Àç°í ¼ö·®ÀÌ ºÎÁ·ÇÕ´Ï´Ù.", vbCritical
                cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·®
            End If
            UserForm1.Hide
            Exit Sub
        End If
    Next cell

    MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù.", vbExclamation
    UserForm1.Hide
End Sub

¸ðµâ2 ÄÚµå

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End

¸ðµâ2¿¡¼­´Â À¯ÀúÆûÀ» ÃʱâÈ­ÇÏ°í ¼³Á¤ÇÏ´Â ÀÛ¾÷¸¸ ÀÖ½À´Ï´Ù. À§ Äڵ带 °¢°¢ÀÇ ¸ðµâ¿¡ º¹»çÇÏ¿© ºÙ¿©³ÖÀ¸¸é ¿À·ù ¾øÀÌ Á¤»ó µ¿ÀÛÇÒ °ÍÀÔ´Ï´Ù.

´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 13:44
°ø±¸ Ãâ°í½Ã ¿¡·¯°¡ ³ª³×¿ä. Sub Ãâ°í() Dim ws1 As Worksheet, ws2 As Worksheet Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â ³¯Â¥ = UserForm1.txtDate.Value Á¾·ù = UserForm1.cboType.Value Ç°¸í = UserForm1.cboName.Value ¼ö·® = UserForm1.cboQuantity.Value ´ã´çÀÚ = UserForm1.cboPerson.Value ºñ°í = UserForm1.txtNote.Value ' ½ÃÆ® ÇÒ´ç Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®") Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®") ' Ãâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡ With ws2 Dim LastRow As Long LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1 .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥ .Cells(LastRow, 2).Value = Á¾·ù .Cells(LastRow, 3).Value = Ç°¸í .Cells(LastRow, 4).Value = ¼ö·® .Cells(LastRow, 5).Value = ´ã´çÀÚ .Cells(LastRow, 6).Value = ºñ°í .Cells(LastRow, 7).Value = "Ãâ°í" End With ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® Dim rg As Range Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row) Dim cell As Range For Each cell In rg If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then cell.Offset(, 2).Value = cell.Offset(, 2).Value - ¼ö·® If cell.Offset(, 2).Value < Then MsgBox "Àç°í ¼ö·®ÀÌ ºÎÁ·ÇÕ´Ï´Ù.", vbCritical cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·® End If UserForm1.Hide Exit Sub End If Next cell
     
       
AIê 2024-06-28 (±Ý) 13:44
@´ç±ÙÆDZÙ

¾Æ·¡¿Í °°ÀÌ ÀϺΠ·ÎÁ÷ ¿À·ù¸¦ ¼öÁ¤ÇÑ Äڵ带 Á¦°øÇÕ´Ï´Ù. ƯÈ÷, 'Ãâ°í' ½Ã Àç°í ¼ö·®À» ¾÷µ¥ÀÌÆ® ÇÒ ¶§ ¹ß»ýÇÏ´Â ¿¡·¯¸¦ ó¸®ÇÕ´Ï´Ù:

  1. If cell.Offset(, 2).Value < Then Á¶°Ç½Ä¿¡¼­ À߸øµÈ ±âÈ£ (< ) ºÎºÐÀ» ``À¸·Î ¼öÁ¤ÇÏ¿´½À´Ï´Ù.
  2. Àç°í ¼ö·®ÀÌ ºÎÁ·ÇÑ °æ¿ì ¿ø·¡ ¼ö·®À¸·Î º¹±¸ÇÏ´Â ·ÎÁ÷À» °³¼±ÇÏ¿´½À´Ï´Ù.

¸ðµâ1 ÄÚµå

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "ÀÔ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·®
            UserForm1.Hide
            Exit Sub
        End If
    Next cell

    ' Á¾·ù¿Í Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾øÀ» °æ¿ì Ãß°¡
    Dim NewRow As Long
    NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
    ws1.Cells(NewRow, 1).Value = Á¾·ù
    ws1.Cells(NewRow, 2).Value = Ç°¸í
    ws1.Cells(NewRow, 3).Value = ¼ö·®

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' Ãâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 2).Value = Á¾·ù
        .Cells(LastRow, 3).Value = Ç°¸í
        .Cells(LastRow, 4).Value = ¼ö·®
        .Cells(LastRow, 5).Value = ´ã´çÀÚ
        .Cells(LastRow, 6).Value = ºñ°í
        .Cells(LastRow, 7).Value = "Ãâ°í"
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            If cell.Offset(, 2).Value >= ¼ö·® Then
                cell.Offset(, 2).Value = cell.Offset(, 2).Value - ¼ö·®
                UserForm1.Hide
            Else
                MsgBox "Àç°í ¼ö·®ÀÌ ºÎÁ·ÇÕ´Ï´Ù.", vbCritical
            End If
            Exit Sub
        End If
    Next cell
    
    MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù.", vbExclamation
    UserForm1.Hide
End Sub

À¯ÀúÆû (UserForm) ÄÚµå

¾Æ·¡ Äڵ带 UserForm1ÀÇ ÄÚµå â¿¡ »ðÀÔÇϼ¼¿ä:

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")
    
    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Format(Date, "yymmdd") ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù (Çü½Ä: yymmdd).
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' TXTDate Ŭ¸¯ ½Ã ³¯Â¥ ¼±ÅÃ¿ë ±âº» ÀÔ·ÂÇü½ÄÀ¸·Î Àüȯ
    txtDate.Value = Format(InputBox("³¯Â¥¸¦ yymmdd Çü½ÄÀ¸·Î ÀÔ·ÂÇϼ¼¿ä.", "³¯Â¥ ÀÔ·Â", txtDate.Value), "yymmdd")
End Sub

¸ðµâ2 ÄÚµå

¾Æ·¡ Äڵ带 Module2¿¡ »ðÀÔÇϼ¼¿ä:

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End

ÀÌ·¸°Ô ¼öÁ¤Çϸé Ãâ°í ½Ã Àç°í ¼ö·®ÀÌ ºÎÁ·ÇÏ¸é ¿À·ù ¸Þ½ÃÁö¸¦ Ç¥½ÃÇÏ°í, ÃæºÐÇÑ Àç°í°¡ ÀÖÀ» °æ¿ì ¼ö·®À» »¬ ¼ö ÀÖ½À´Ï´Ù. ³¯Â¥ ÀÔ·Â Çü½Äµµ yymmdd·Î ÁöÁ¤ÇÏ¿´½À´Ï´Ù. À§ ÄÚµåµéÀ» °¢°¢ÀÇ ¸ðµâ¿¡ º¹»çÇÏ¿© ³ÖÀ¸¸é Á¤»ó µ¿ÀÛÇÒ °ÍÀÔ´Ï´Ù.

´ç±ÙÆDZٱ۾´ÀÌ 2024-06-28 (±Ý) 13:55
³¯Â¥°¡ Á¦´ë·Î ÀÛµ¿ÇÏÁö ¾Ê¾Æ¿ä. ÅؽºÆ® ÀÔ·Â ¸»°í ´Þ·ÂÀ» ¶ç¿ö¼­ ¼±ÅÃÇÒ ¼ö´Â ¾ø³ª¿ä? ±×¸®°í ÀÔ°í,Ãâ°í ±â·Ï ¸®½ºÆ®¿¡ ÀÔ°í,Ãâ°í ±¸ºÐÇÏ´Â ¿­ÀÌ a¿­·Î ¿ÔÀ¸¸é ÁÁ°Ú¾î¿ä.
     
       
AIê 2024-06-28 (±Ý) 13:55
@´ç±ÙÆDZÙ

³¯Â¥ ÀÔ·ÂÀ» À§ÇØ ´Þ·ÂÀ» ¶ç¿ì´Â ¹æ¹ýÀº Microsoft MonthView Control (MSCOMCTL.OCX) ¶Ç´Â Microsoft Date and Time Picker Control (MSCOMCT2.OCX)À» »ç¿ëÇÏ´Â °ÍÀÔ´Ï´Ù. µÎ ÄÁÆ®·Ñ ¸ðµÎ Excel ¼³Ä¡ ¹× ½Ã½ºÅÛ¿¡¼­ »ç¿ë °¡´ÉÇØ¾ß ÇÕ´Ï´Ù.

¼Â¾÷À» À§ÇØ ÇÊ¿äÇÑ »çÇ×:

  1. MonthView ¶Ç´Â DatePicker µî·Ï:
    • MSCOMCTL.OCX ¶Ç´Â MSCOMCT2.OCX°¡ System32 µð·ºÅ丮¿¡ ÀÖ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
    • ¸í·É ÇÁ·ÒÇÁÆ®(cmd)¸¦ °ü¸®ÀÚ ±ÇÇÑÀ¸·Î ½ÇÇàÇÑ ´ÙÀ½, ´ÙÀ½ ¸í·É¾î¸¦ ÀÔ·ÂÇÏ¿© ÇØ´ç ÄÁÆ®·ÑÀ» µî·ÏÇÕ´Ï´Ù.
      regsvr32 C:\Windows\System32\mscomctl.ocx
      regsvr32 C:\Windows\System32\mscomct2.ocx
      

À¯ÀúÆû¿¡ ´Þ·Â ÄÁÆ®·Ñ Ãß°¡:

  1. VBA ÆíÁý±â¿¡¼­ ÄÁÆ®·Ñ Ãß°¡:
    • VBA ÆíÁý±â(ALT + F11)¸¦ ¿­°í, µµ±¸ »óÀÚ¿¡¼­ Additional Controls¸¦ ¼±ÅÃÇÕ´Ï´Ù.
    • Microsoft MonthView Control 6. ¶Ç´Â Microsoft Date and Time Picker Control 6.À» ã¾Æ üũÇÏ°í OK¸¦ ´©¸¨´Ï´Ù.
    • µµ±¸ »óÀÚ¿¡¼­ ÇØ´ç ÄÁÆ®·ÑÀ» À¯ÀúÆû¿¡ Ãß°¡ÇÕ´Ï´Ù.

À̸¦ ÅëÇØ ³¯Â¥¸¦ ¼±ÅÃÇÒ ¼ö ÀÖ´Â ´Þ·ÂÀ» º¸¿©ÁÖµµ·Ï ÇÏ°í, ¹öÆ° ¹× ¶óº§ °ü·Ã ¹®±¸¸¦ ¼öÁ¤ÇÏ´Â ¹æ¹ýÀ» Æ÷ÇÔÇÏ´Â Äڵ带 Á¦°øÇÕ´Ï´Ù. ¶ÇÇÑ ÀÔ°í ¹× Ãâ°í ±â·Ï ¸®½ºÆ®¿¡¼­ 'ÀÔ°í'/'Ãâ°í' ±¸ºÐ¿­À» A¿­·Î À̵¿ÇÕ´Ï´Ù.

À¯ÀúÆû (UserForm) ¼öÁ¤ ÄÚµå

¸ÕÀú ´Þ·Â ÄÁÆ®·ÑÀ» ¼³Á¤ÇÏ°í UserForm¿¡ Ãß°¡Çß´ÂÁö È®ÀÎÇϽʽÿÀ. Ãß°¡µÈ ´Þ·Â ÄÁÆ®·ÑÀÇ À̸§À» MonthView1 ¶Ç´Â DatePicker1·Î Çß´Ù°í °¡Á¤ÇÕ´Ï´Ù. (MonthView¸¦ »ç¿ëÇÏ´Â ¿¹½Ã·Î Á¦°øÇÏ¿´À¸³ª DatePickerµµ À¯»çÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù).

Private Sub UserForm_Initialize()
    ' µ¥ÀÌÅÍ ½ÃÆ®¿¡¼­ ÄÞº¸¹Ú½º µ¥ÀÌÅ͸¦ ·Îµå
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    ' Á¾·ù ·Îµå
    cboType.Clear
    Dim rngType As Range
    Set rngType = wsData.Range("A2:A" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
    Dim cell As Range
    Dim typeDict As Object
    Set typeDict = CreateObject("Scripting.Dictionary")

    For Each cell In rngType
        If cell.Value <> "" And Not typeDict.exists(cell.Value) Then
            cboType.AddItem cell.Value
            typeDict.Add cell.Value, Nothing
        End If
    Next cell

    ' ´ã´çÀÚ ·Îµå
    cboPerson.Clear
    Dim rngPerson As Range
    Set rngPerson = wsData.Range("C2:C" & wsData.Cells(wsData.Rows.Count, 3).End(xlUp).Row)
    For Each cell In rngPerson
        If cell.Value <> "" Then
            cboPerson.AddItem cell.Value
        End If
    Next cell

    ' ¼ö·® ·Îµå
    cboQuantity.Clear
    Dim i As Integer
    For i = 1 To 100 ' ¿øÇÏ´Â ¼ö·®±îÁö Ãß°¡
        cboQuantity.AddItem i
    Next i

    ' ÆûÀÇ ¸ðµç ÀÔ·Â Çʵ带 ÃʱâÈ­
    cboType.Value = ""
    cboName.Clear ' ÃʱâÈ­ÇÒ ¶§´Â Ç°¸í Çʵ带 ºñ¿öµÓ´Ï´Ù.
    cboQuantity.Value = ""
    cboPerson.Value = ""
    txtNote.Value = ""
    txtDate.Value = Format(Date, "yymmdd") ' ¿À´Ã ³¯Â¥·Î ÃʱâÈ­ÇÕ´Ï´Ù (Çü½Ä: yymmdd).
    
    ' ´Þ·ÂÀ» ¼û±â±â
    MonthView1.Visible = False
End Sub

Private Sub cboType_Change()
    ' Á¾·ù ¼±Åà ½Ã Ç°¸í ¾÷µ¥ÀÌÆ®
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("µ¥ÀÌÅÍ ½ÃÆ®")

    Dim selectedType As String
    selectedType = cboType.Value

    cboName.Clear
    If selectedType <> "" Then
        Dim rngName As Range
        Set rngName = wsData.Range("A2:B" & wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row)
        Dim cell As Range
        For Each cell In rngName
            If cell.Value = selectedType And cell.Offset(, 1).Value <> "" Then
                cboName.AddItem cell.Offset(, 1).Value
            End If
        Next cell
    End If
End Sub

Private Sub btnEnter_Click()
    Call ÀÔ°í
End Sub

Private Sub btnExit_Click()
    Call Ãâ°í
End Sub

Private Sub txtDate_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' ´Þ·Â º¸À̱â
    MonthView1.Value = Date
    MonthView1.Visible = True
End Sub

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    ' ´Þ·Â ³¯Â¥ ¼±Åà ½Ã ÅؽºÆ®¹Ú½º¿¡ ³¯Â¥ ¼³Á¤
    txtDate.Value = Format(MonthView1.Value, "yymmdd")
    MonthView1.Visible = False
End Sub

¸ðµâ1 ¼öÁ¤ ÄÚµå

ÀÔ°í ¹× Ãâ°í ±â·Ï ¸®½º¿¡¼­ 'ÀÔ°í'/'Ãâ°í' ±¸ºÐÀ» A¿­·Î À̵¿ÇÕ´Ï´Ù.

Sub ÀÔ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' ÀÔÃâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = "ÀÔ°í"
        .Cells(LastRow, 2).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 3).Value = Á¾·ù
        .Cells(LastRow, 4).Value = Ç°¸í
        .Cells(LastRow, 5).Value = ¼ö·®
        .Cells(LastRow, 6).Value = ´ã´çÀÚ
        .Cells(LastRow, 7).Value = ºñ°í
    End With

    ' Àç°í ¸®½ºÆ®¿¡ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ® ¶Ç´Â Ãß°¡
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            cell.Offset(, 2).Value = cell.Offset(, 2).Value + ¼ö·®
            UserForm1.Hide
            Exit Sub
        End If
    Next cell

    ' Á¾·ù¿Í Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾øÀ» °æ¿ì Ãß°¡
    Dim NewRow As Long
    NewRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
    ws1.Cells(NewRow, 1).Value = Á¾·ù
    ws1.Cells(NewRow, 2).Value = Ç°¸í
    ws1.Cells(NewRow, 3).Value = ¼ö·®

    UserForm1.Hide
End Sub

Sub Ãâ°í()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ³¯Â¥ As String, Á¾·ù As String, Ç°¸í As String, ¼ö·® As Integer, ´ã´çÀÚ As String, ºñ°í As String

    ' UserForm¿¡¼­ µ¥ÀÌÅÍ °¡Á®¿À±â
    ³¯Â¥ = UserForm1.txtDate.Value
    Á¾·ù = UserForm1.cboType.Value
    Ç°¸í = UserForm1.cboName.Value
    ¼ö·® = UserForm1.cboQuantity.Value
    ´ã´çÀÚ = UserForm1.cboPerson.Value
    ºñ°í = UserForm1.txtNote.Value

    ' ½ÃÆ® ÇÒ´ç
    Set ws1 = ThisWorkbook.Sheets("Àç°í ¸®½ºÆ®")
    Set ws2 = ThisWorkbook.Sheets("ÀÔÃâ°í ±â·Ï ¸®½ºÆ®")

    ' Ãâ°í ±â·Ï ¸®½ºÆ®¿¡ Ãß°¡
    With ws2
        Dim LastRow As Long
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(LastRow, 1).Value = "Ãâ°í"
        .Cells(LastRow, 2).Value = ³¯Â¥ ' ³¯Â¥
        .Cells(LastRow, 3).Value = Á¾·ù
        .Cells(LastRow, 4).Value = Ç°¸í
        .Cells(LastRow, 5).Value = ¼ö·®
        .Cells(LastRow, 6).Value = ´ã´çÀÚ
        .Cells(LastRow, 7).Value = ºñ°í
    End With

    ' Àç°í ¸®½ºÆ®¿¡¼­ ±âÁ¸ ¼ö·® ¾÷µ¥ÀÌÆ®
    Dim rg As Range
    Set rg = ws1.Range("A2:A" & ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row)
    Dim cell As Range
    For Each cell In rg
        If cell.Value = Á¾·ù And cell.Offset(, 1).Value = Ç°¸í Then
            If cell.Offset(, 2).Value >= ¼ö·® Then
                cell.Offset(, 2).Value = cell.Offset(, 2).Value - ¼ö·®
                UserForm1.Hide
            Else
                MsgBox "Àç°í ¼ö·®ÀÌ ºÎÁ·ÇÕ´Ï´Ù.", vbCritical
            End If
            Exit Sub
        End If
    Next cell
    
    MsgBox "ÇØ´ç Ç°¸íÀÌ Àç°í ¸®½ºÆ®¿¡ ¾ø½À´Ï´Ù.", vbExclamation
    UserForm1.Hide
End Sub

¸ðµâ2 ¼öÁ¤ ÄÚµå

Sub ShowEnterForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "ÀÔ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = True
        .btnExit.Visible = False
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End

Sub ShowExitForm()
    ' À¯ÀúÆû ÃʱâÈ­ ¹× ¼³Á¤
    With UserForm1
        .Caption = "Ãâ°í Á¤º¸ ÀÔ·Â"
        .btnEnter.Visible = False
        .btnExit.Visible = True
        .txtDate.Visible = True
        .lblDate.Visible = True
        .Show
    End With
End Sub

ÀÌ·¸°Ô ¼öÁ¤ÇÑ ÄÚµå´Â ´Þ·Â ÄÁÆ®·ÑÀ» ÅëÇØ ³¯Â¥¸¦ ¼±ÅÃÇÒ ¼ö ÀÖ°Ô Çϸç, ÀÔ°í ¹× Ãâ°í ±â·Ï ¸®½ºÆ®¿¡¼­ 'ÀÔ°í'/'Ãâ°í' ±¸ºÐÀ» A¿­·Î À̵¿ÇÕ´Ï´Ù. txtDate ÅؽºÆ®¹Ú½º¸¦ Ŭ¸¯ÇÏ¿© ´Þ·ÂÀ» ÅëÇØ ³¯Â¥¸¦ ½±°Ô ¼±ÅÃÇÒ ¼ö ÀÖ°Ô Çϸç, ¼±ÅÃµÈ ³¯Â¥´Â yymmdd Çü½ÄÀ¸·Î Æ÷¸ËµÇ¾î ÅؽºÆ® ¹Ú½º¿¡ Ãß°¡µË´Ï´Ù.


óÀ½  1  2  3  4  5  6  7  8  9  10  ´ÙÀ½ ´ÙÀ½°Ë»ö

°øÀ¯Çϱâ

ÀÌÅä·£µå ·Î°í

°èÁ¤ ã±â ȸ¿ø°¡ÀÔ
¼Ò¼È·Î±×ÀÎ