VBA」タグアーカイブ

[VBA]シートコピー

Private Sub copy_all()
    Dim i As Integer
    
    For i = 1 To 41
        'Worksheets.Add After:=Sheets(Sheets.Count)  '最後にシート作成
        Workbooks("true.xls").Worksheets("書換中").Copy After:=Workbooks("detabase.xls").Sheets("使い方")
        Workbooks("detabase.xls").ActiveSheet.Name = Workbooks("true.xls").Worksheets(1).Cells(i, 4)
        Workbooks("detabase.xls").ActiveSheet.Range("C1") = Workbooks("true.xls").Worksheets(1).Cells(i, 4)
        Workbooks("detabase.xls").ActiveSheet.Range("G2") = "(追加)"
    Next
End Sub

更新@2011.01.04 23:40

excelマクロ基本

演算子

IF 条件 Then
 何たら
End If

 ↑↓ どちらでも良

IF 条件 Then 何たら

※1行のときEnd Ifが要らない。ただし1行の処理のみ

接続詞

Cells(i + 5, 15).Hyperlinks.Add anchor:=Cells(i + 5, 15), _
           Address:="", SubAddress:="'" + text + "'!A1"

※2行に書き分けるときは『 _』を最後に書く
 『_』の前に半角SP忘れずに。

更新@2011.01.05 00:10

[VBA]マス比較

Private Sub onajika()
    Dim i As Integer
    Dim j As Integer
    Dim cnt As Integer
    cnt = 1
    Dim tt As Integer
    tt = 0
    Dim wk As Integer
    wk = 1
    
    For i = 1 To 102 'Worksheets(wk).Cells.Count
        tt = 0
        For j = 1 To 102 'Worksheets(wk).Cells.Count
            If Worksheets(wk).Cells(i, 1).Value = Worksheets(wk).Cells(j, 2) Then
                tt = 1
                Exit For
            End If
        Next
        If tt = 0 Then
           Worksheets(wk).Range("C" & i).Value = Worksheets(wk).Cells(i, 1).Value
           Worksheets(wk).Range("D" & cnt).Value = Worksheets(wk).Cells(i, 1).Value
           cnt = cnt + 1
        End If
    Next
End Sub

更新@2011.03.03 22:43