エクセルvbaメモ 最終行を取得する

2014年6月14日土曜日

MicrosoftOffice

t f B! P L

' A行の最終行数を取得
Dim c As Integer
c = ActiveSheet.Range("A1").End(xlDown).Row



追記メモ再

'フォーム初期化時のイベント(用意されたメソッドのオーバーライド?)
Private Sub UserForm_Initialize()


' シート名のチェックボックスを作成
Public Sub CommandButton1_Click()
    Dim s As Integer
    Dim myCheckBox As Control
 
    '品種数
    Dim kCount As Integer
    kCount = 0
    '1品種中のライン数
    Dim lCount As Integer
    lCount = 0
 
    '項目数のカウント
    Dim aCount As Integer
    aCount = ActiveSheet.Range("B3").End(xlDown).Row
 

    For s = 3 To aCount
        If Cells(s, 2).Value <> Cells(s - 1, 2).Value Then
            ' 品名フレーム生成
            Set myFrame = Me.Controls.Add("Forms.Frame.1")
            With myFrame
                .Height = 30
                .Width = 240
                .Left = 10
                .Top = (kCount) * (.Height + 5) + 50
                .Name = Cells(s, 2).Value       '品名
                .Caption = Cells(s, 2).Value    '品名
            End With
         
            '品種数カウント
            kCount = kCount + 1
            '1品種中のライン数のカウントリセット
            lCount = 1

        End If
     
        ' チェックボックス生成
        Set myCheckBox = myFrame.Controls.Add("Forms.CheckBox.1")
        With myCheckBox
            .Height = 20
            .Width = 40
            .Left = (lCount - 1) * .Width + 10 '50
            .Top = 5 '(s - 2) * .Height + 5
            .Name = Cells(s, 2).Value       '品名
            .Caption = Cells(s, 3).Value    'ラインNo
            .Tag = Cells(s, 4).Value        'マシン名
        End With
        lCount = lCount + 1

    Next s
 
    'フォームのサイズ変更
    UserForm1.Height = 80 + kCount * 35
 
End Sub

' チェックしたシートを印刷
Private Sub CommandButton2_Click()
    Dim mch As Control
 
    For Each mch In Controls
        If TypeName(mch) = "CheckBox" Then
            If mch.Value = True Then
                Cells(1, 10).Value = mch.Caption
                Cells(1, 11).Value = mch.Tag
                Cells(1, 12).Value = mch.Name
                'Sheets(mch.Caption).PrintOut
            End If
        End If
    Next mch
 
End Sub


Translate

このブログを検索

  • ()
  • ()
もっと見る

QooQ