Excel �iVBA�j

Excel VBA�Ɋւ���t�H�[�����ł��B
  • �����ς݂̃g�s�b�N�ɂ̓R�����g�ł��܂���B
���̃g�s�b�N�͉����ς݂ł��B
����

 
(�w��Ȃ� : �w��Ȃ�)
RE�F�@���v�ƍ��v�����ׂ�
���e����: 25/11/20 21:07:55
���e��: simple

�������ꂽ�悤�ł����A�Q�l���������Ă����܂��B
 
���\�`���ɕϊ������̂��A���v�p�Z���𖄂ߍ��ޕ��@
 

�y�}�N�����s�O�z              �y�}�N�����s��z
      A��                           A��         B��
1     ��������                1     ��������    
2     �e�q���~�Q              2     �e�q��      2
3     �V���~�Q         ��     3     �V��        2
4     �e�q���~�R              4     �e�q��      3
5     �V���~�R                5     �V��        3
6     �e�q���~�R              6     �e�q��      3
7     �e�q���~�Q              7     �e�q��      2
8     �����v��                8     �����v��    
                              9     �e�q��     10
                             10     �V��        5
                             
                             B9�Z�� �@=SUMIF($A$2:$A$7,A9,$B$2:$B$7)
                             B10�Z���@=SUMIF($A$2:$A$7,A10,$B$2:$B$7)

�y�}�N����z
Rem �\�`���ɕϊ������̂��A���v�p�Z���𖄂ߍ���
Sub test1()
    Dim pos&
    Dim dic     As Object
    Dim key
    Dim outputRng As Range
    Dim adres1$, adres2$, adres3$
    Dim k&
    
    '1�Z������Q�Z���ɓW�J
    pos = Application.Match("�����v��", Columns(1), 0)
    Range("A2", Cells(pos - 1, "A")).TextToColumns _
        Destination:=Range("A2"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, _
        OtherChar:="�~", FieldInfo:=Array(Array(1, 1), Array(2, 1)), _
        TrailingMinusNumbers:=True

    '���j�[�N�ȗ��������擾
    Set dic = CreateObject("Scripting.Dictionary")
    For k = 2 To pos - 1
        dic(Cells(k, "A").Text) = Empty
    Next
    
    '�������̏�������
    Set outputRng = Cells(Rows.Count, "A").End(xlUp).Offset(1)
    outputRng.Resize(dic.Count) = Application.Transpose(dic.keys)

    '���v�Z���̖��ߍ���
    adres1 = Range("A2", Cells(pos - 1, "A")).Address
    adres2 = Range("B2", Cells(pos - 1, "B")).Address
    adres3 = outputRng.Address(False, False)
    outputRng.Offset(, 1).Resize(dic.Count).Formula = _
            "=SUMIF(" & adres1 & "," & adres3 & "," & adres2 & ")"
End Sub

�y���̕����̃����b�g�z
�E�W���I�ȕ\�`���ƂȂ��Ă���
�E����ύX����Ǝ����ō��v���X�V�����
�E�����̗������ł���΁A�s�̒lj��A�폜�ɂ��Ή����č��v���������ŏC�������B
  �i�������A���������lj����ꂽ��A�S�̂�������x�쐬���Ȃ����K�v������j

���e����: 25/11/20 21:10:12
���e��: simple

������̃t�H�[�}�b�g�̂܂܁A���ق�����Ε\�������������
 

     A��
1     ��������
2     �e�q���~�Q
3     �V���~�Q
4     �e�q���~�R
5     �V���~�R
6     �e�q���~�R
7     �e�q���~�Q
8     �����v��
9     �e�q���~�X �V���~�T
10    �e�q���� 10 ��������  ���}�N�����s��A���ق�����ΐԎ��ŒNjL����

�y�}�N����z
Sub test2()
    Dim pos&
    Dim k&, s$
    Dim ary     As Variant
    Dim rng     As Range
    Dim elem    As Variant
    Dim dic     As Object

    pos = Application.Match("�����v��", Columns(1), 0)
    Set dic = CreateObject("Scripting.Dictionary")
    
    '�������A���̓ǂݍ��݁B���v���̌v�Z
    For k = 2 To pos - 1
        s = Cells(k, "A")
        ary = Split(s, "�~")
        dic(ary(0)) = dic(ary(0)) + CLng(ary(1))
    Next

    '���v���̃Z���ʒu
    Set rng = Cells(Rows.Count, "A").End(xlUp)

    '���v���̌���
    For Each elem In Split(rng, " ")
        ary = Split(elem, "�~")
        If CLng(ary(1)) <> dic(ary(0)) Then
            Set rng = rng.Offset(1)
            rng.Value = ary(0) & "�� " & dic(ary(0)) & " ��������"
            rng.Font.Color = vbRed
        End If
    Next
End Sub

�y���l�z
�����܂ł������̗������ƍ��v�̃`�F�b�N�Ȃ̂ŁA�������ɐV�K���������lj�����Ă��Ă����m���Ȃ��B
�i�ނ��A�}�N�����C������΁A�o�����̃`�F�b�N�͉”\�B�������Ă݂Ă��������j
 
�]��O����ɂ݂Ă��Ȃ��̂ŁA�����Ƃ��͂��邩������܂���B

���e����: 25/11/21 22:40:01
���e��: simple

�‚��܂��B