我知道0%的VBA,我需要帮助。我需要创建一个VBA按钮,突出显示一行单元格,然后向下移动1,然后当单击该按钮时,它将重复上述过程。
以下是我所谈论的片段:
我只想让上面的内容向下移动到下一行然后突出显示那3列并重复。
如果您知道如何为“x”行数据实现此功能,请告诉我。
谢谢!
编辑:我尝试过的代码
Private Sub CommandButton1_Click()
Sub Macro1()
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("A12:C12").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("A13:C13").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
答案 0 :(得分:0)
我已经尝试了以下内容,它可以按照您的意愿运行:
Sub Button1_Click()
LastRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row 'Check the last row with data
For i = 1 To LastRow 'loop until you find the last highlighted cell
If Sheet1.Cells(i, 1).Interior.Color = 65535 Then
x = i + 1 ' add one for the next row
End If
Next i
If x > 1 Then
Sheet1.Range("A" & x & ":C" & x).Interior.Color = 65535 'add colour to the next cell found in previous loop
Else
x = 1
Sheet1.Range("A" & x & ":C" & x).Interior.Color = 65535 'if no cell found in previous loop, highlight the first row
End If
End Sub
答案 1 :(得分:0)
这将突出显示所选行并向下移动一行。然后等待下一个按钮按下。
Option Explicit
Private Sub HighlightSelectedRowAndMoveDown()
With Selection.EntireRow 'use the entire row of the selected cell
.Interior.Color = 65535 'color its background yellow
.Offset(1, 0).Select 'move selection one row down
End With
End Sub