あけましておめでとうございます。pipiでございます。
本年も宜しくお願い致します。
リストボックス内の数字を右揃えにするため、Space()関数を使い自作の関数を作成したが、
綺麗に右揃えになってくれません。微妙に中央揃えになっている気がします。。。
'Space挿入関数 '<引数について> 'strName:対象となる文字列 'intMojiCount:スペース挿入後の全体の文字数 'isTop:先頭から処理する(true) Public Function FormatAddSpace(ByVal strName As String, ByVal intMojiCount As Integer, _ Optional ByVal isTop As Boolean = True) As String Dim n As Integer n = intMojiCount - Len(strName) '全体の文字数から対象となる文字列を引いた数分、スペース挿入 If isTop = True Then strName = Space(n) & strName '先頭にスペース挿入 End If FormatAddSpace = strName End Function
'リストボックス設定抜粋コード With ListBox1 .Font.Size = 10 .ColumnCount = 7 .ColumnWidths = "50;100;80;80;100;30;70" .TextAlign = fmTextAlignLeft .Font.Name = "MS ゴシック" Dim i As Long Dim LastRow As Long LastRow = Range("A600").End(xlUp).Row For i = 2 To LastRow If Cells(i, 8).Value <> 1 Then .AddItem FormatAddSpace(Cells(i, 1).Value, 4) '商品ID、全体の文字数を4としてFormatAddSpace関数を呼び出す。 .List(.ListCount - 1, 1) = Cells(i, 2).Value .List(.ListCount - 1, 2) = Cells(i, 3).Value .List(.ListCount - 1, 3) = Cells(i, 4).Value .List(.ListCount - 1, 4) = FormatAddSpace(Cells(i, 5).Value, 7) '単価、全体の文字数を7としてFormatAddSpace関数を呼び出す。 .List(.ListCount - 1, 5) = Cells(i, 6).Value .List(.ListCount - 1, 6) = Cells(i, 7).Value End If Next End With
どなたか、アドバイス、ご教授願います。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/01/02 00:48
2016/01/02 01:16