0

特定の名前のヘッダー列「DATA/HORA」を検索して、以下のマクロに適応するにはどうすればよいですか?

Sub Data()

Dim cell As Range
Dim lastRow As Long

lastRow = Range("A" & Rows.Count).End(xlUp).Row

For Each cell In Range("A1:A" & lastRow)
 If InStr(cell.Value, "-") <> 0 Then
    cell.Value = RegexReplace(cell.Value, _
    "(\d{4})\-(\d{2})\-(\d{2})", "$3/$2/$1")
End If

 cell.NumberFormat = "dd/mm/yyyy;@"
Next

End Sub

Function RegexReplace
------    
End Function
4

1 に答える 1

1

交換:

lastRow = Range("A" & Rows.Count).End(xlUp).Row
For Each cell In Range("A1:A" & lastRow)

と:

Dim ColLetr As String
For i = 1 To Columns.Count
    If Cells(1, i) = "DATA/HORA" Then
        ColLetr = Split(Cells(1, i).Address, "$")(1)
    End If
Next
lastRow = Range(ColLetr & Rows.Count).End(xlUp).Row
For Each cell In Range(ColLetr & "1:" & ColLetr & lastRow)

編集#1

コメントに対処するには:

Dim ColLetr As String
For i = 1 To Columns.Count
    If Cells(1, i) = "DATA/HORA" Then
        ColLetr = Split(Cells(1, i).Address, "$")(1)
        Exit For
    End If
Next
If ColLetr = "" Then
    MsgBox "DATA/HORA not found"
    Exit Sub
End If
lastRow = Range(ColLetr & Rows.Count).End(xlUp).Row
For Each cell In Range(ColLetr & "1:" & ColLetr & lastRow)
于 2013-10-27T13:25:24.203 に答える