简体   繁体   English

Excel中的动态单元格格式

[英]Dynamic cell formatting in excel

I have a VBA that will pull rows from another spreadsheet.我有一个 VBA,可以从另一个电子表格中提取行。 The problem is I am trying to dynamically format the cells that are populated with the rows information.问题是我正在尝试动态格式化填充有行信息的单元格。 At the moment I have formatted row 11 however, how can I set it so that any the rows are populated will be formatted in a white bordered cell.目前我已经格式化了第 11 行,但是,如何设置它以便填充的任何行都将被格式化为白色边框单元格。 and when they are not populated they will just be greyed out.当它们没有填充时,它们只会变灰。

Sub Searchdata()
Dim Lastrow As Long
Dim count As Integer
Lastrow = Sheets("Data").Cells(Rows.count, 1).End(xlUp).Row
Y = 11
For X = 2 To Lastrow
If Sheets("Data").Cells(X, 1) = Sheet3.Range("B3") Then
   Sheet3.Cells(Y, "A") = Sheets("Data").Cells(X, 1)
   Sheet3.Cells(Y, "B") = Sheets("Data").Cells(X, 2)
   Sheet3.Cells(Y, "C") = Sheets("Data").Cells(X, 3) & " " & Sheets("data").Cells(X, 4) _
                            & " " & Sheets("data").Cells(X, 5) & " " & Sheets("Data").Cells(X, 6)
   Sheet3.Cells(Y, "D") = Sheets("Data").Cells(X, 7)
   Y = Y + 1
End If
Next X
End Sub

在此处输入图片说明

Right after your if statement add the following lines:在 if 语句之后添加以下行:

    With range(Cells(Y, 1), Cells(Y, "D"))
        .Interior.ColorIndex = xlNone
        With .Borders
            .LineStyle = xlContinuous
            .Color = vbBlack
            .Weight = xlThin
        End With
    End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM