excel表中应该只有一个标题

时间:2013-04-11 14:41:47

标签: excel excel-vba vba

enter image description here

我必须格式化Excel工作表。它包含多个空行,几行后重复的haeders。新的vb脚本和这种类型的excel工作。我怎样才能做到这一点。有人可以帮助我进行宏编码吗???这是快照

1 个答案:

答案 0 :(得分:1)

我会用for / next循环处理一个项目。 您可以获取报告中的总行数,以便了解何时停止查找要格式化的内容。您可以使用if和end if语句在循环中进行任何类型的测试。 下面是一个更改第一列中任何数据格式的示例。

Option Explicit
Sub Format_Report()

Dim Nbr_of_Sheets As Integer
Dim LastLine_Data As Long
Dim Loop_Ctr As Long
Dim LastLine_Plug_Code As Long

Application.ScreenUpdating = False

Nbr_of_Sheets = ActiveWorkbook.Sheets.Count

Sheet1.Select  ' Always select sheet 1 no matter what the name
Range("A1").Select
LastLine_Data = Cells(Rows.Count, "A").End(xlUp).Row
For Loop_Ctr = 1 To LastLine_Data
    If Cells(Loop_Ctr, 1).Value <> "" Then

        With Cells(Loop_Ctr, 1)
            .Font.Bold = True
            .Font.Name = "Arial Black"
            .Font.Size = 14
        End With

    End If
Next Loop_Ctr
Application.ScreenUpdating = True

End Sub