2010-12-02 5 views
1

Excel 행에 값을 인쇄하고 싶습니다. 내가 행을 선택하고 그것을 선택할 수 있지만 어떻게 세포를 통해 루프합니까? 아니면 읽을 수있는 행 개체가 있습니까?Excel에서 행 셀 값 인쇄

Range("A1").End(xlUp).Offset(1, 0).Select 

    Do Until IsEmpty(ActiveCell) 

     r = Rows(ActiveCell.Row).EntireRow.Select 

     For Each cell In r.Cells 
      Debug.Print cell.Value 
     Next cell 

    Loop 

답변

2

나는 일을 Do Until IsEmpty 함수 (를 ActiveCell)가`좋은 생각이 아니라고 생각 :
당신이 비어 있지 않은 셀 다음에 약간의 빈 셀을 가질 수있다.

이 코드는 어떤 방식으로 작동합니까?

Sub print_some_values() 

    Dim c As Long 
    Dim r As Long 
    Dim max_col As Long 

    r = ActiveCell.Row 
    max_col = ActiveSheet.UsedRange.Columns.Count 

    For c = 1 To ActiveSheet.UsedRange.Columns.Count 
     Debug.Print ActiveSheet.Cells(r, c).Value 
    Next c 

End Sub 
+0

빈 셀이 맞다면 맞춰보세요. – Lorenzo

1

나는 당신이 달성 하려는지 모르겠지만,이 코드는 빈 셀이

Sub a() 

Dim r As Range 
Dim c As Range 

    Set r = Rows(ActiveCell.Row) 
    For Each c In r.Cells 
     If (IsEmpty(c)) Then Exit For 
     Debug.Print c.Value 
    Next c 

편집

나는이 생각을 찾을 때까지 현재 행을 인쇄 무엇을 찾고 있습니다 :

Sub a() 

Dim TheArray As Variant 

TheArray = Range("A4:E4").Value 
Debug.Print TheArray(1, 4) 

End Sub 
+0

단지 유스 케이스를 명확히하기 위해 모든 행을 거쳐 값을 읽고 SQL Server로 보내기를 원합니다. 이 작업을 수행하는 더 좋은 방법이 있습니까? 행을 레코드 집합 행으로 처리하려고 할 때 재미있는 Excel에는 행의 값을 읽는 것이 더 좋습니다. – Lorenzo

+0

@L. De Leo는 편집을 참조하십시오 –

+0

이것은 Excel의 유일한 MS 참조입니까? http://msdn.microsoft.com/en-us/library/aa272268%28v=office.11%29.aspx – Lorenzo

0

">"행이 더러운 지 알려줍니다 (편집 완료)

Dim r As Range 
Dim c As Range 
Dim max_col As Long 

max_col = ActiveSheet.UsedRange.Columns.Count 

Range("A1").End(xlUp).Offset(1, 0).Select 

Do Until IsEmpty(ActiveCell) 
    Debug.Print ActiveCell.Value 

    If ActiveCell.Value = ">" Then 
     Set r = Rows(ActiveCell.Row) 

     For Each c In r.Cells 
      'print the value of each cell in the row 
      If c.Column = 1 Then 
       'skip 
      ElseIf c.Column <= max_col Then 
       Debug.Print c.Value 
      Else 
       Exit For 
      End If 
     Next c 
    End If 

    ActiveCell.Offset(1, 0).Select 

Loop