2013-08-15 4 views
0

아래 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

단순히

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