我有下面的代码,用于从第6行向下选择C列中的非空单元格。对于所选的每个单元格,我现在希望代码也选择该行的第1列到第10列中的单元格 - 但我正在努力!任何帮助都会很棒!
Sub EnquiryPrep()
Dim x As Integer
Dim rng As Range
With Sheets("Sheet 1")
LR = .Range("C" & Rows.Count).End(xlUp).Row
For Each cell In .Range("C6:C" & LR)
If cell.Value <> "" Then
If rng Is Nothing Then
Set rng = (cell)
Else
Set rng = Union(rng, cell)
End If
End If
Next cell
rng.Select
End With
End Sub
答案 0 :(得分:0)
或许只是
Sub EnquiryPrep()
Dim x As Integer
Dim rng As Range
With Sheets("Sheet 1")
LR = .Range("C" & Rows.Count).End(xlUp).Row
For Each cell In .Range("C6:C" & LR)
If cell.Value <> "" Then
If rng Is Nothing Then
Set rng = cell.offset(, -2).resize(, 10)
Else
Set rng = Union(rng, cell.offset(, -2).resize(, 10))
End If
End If
Next cell
rng.Select
End With
End Sub