2014-09-30 3 views
0

저는 VBA Excel 프로그래밍을 처음 접합니다.VBA 다른 형식의 새 워크 시트에 데이터 가져 오기 Excel

한 시트에서 다른 시트로 다른 형식으로 데이터를 추출해야합니다. 그러나이 튜토리얼의 많은 부분은 행 또는 범위별로 데이터 행을 새로운 시트로 추출하는 것으로 보입니다. 내가 다른 데이터 시트에서 사용자 지정 형식으로 데이터를 만들고 싶어

**School   Principal Student Student ID** 
United College Bill Gates Peter  p3214 
United College Bill Gates Mary  p4213 
United College Bill Gates Forge  p7621 
Beverly High  Melin Brad Goge  p1111 
Beverly High  Melin Brad Fred  p2222 

:

그래서이 내 DataSheet1입니다.

School  United College 
Principal Bill Gates 

Student Student ID 
Peter  p3214 
Mary  p4213 
Forge  p7621 


School  Beverly High 
Principal Melinda Brad 

Student Student ID 
Goge  p1111 
Fred  p2222 

아래는 내 코드의 일부는 시트 2에 Sheet1의에서 얻을 수 있지만 코드는 범위 범위에서 데이터를 얻을 보여줍니다 : 그래서 여기에 내 원하는 결과입니다. 데이터를 사용자 지정 형식으로 추출하는 데 사용해야하는 개념에는 어떤 것이 있습니까? 내가 내 데이터를 입력하고자하는

Dim secondsheet As Worksheet 
Set secondsheet = workbook.Worksheets(2) 
Dim firstsheet As Worksheet 
Set firstsheet = workbook.Worksheets(1) 

secondsheet.Range("A1", "C10").Value = firstsheet.Range("A1", "C10").Value 

그리고 형식 : 내 코드

Range(<<call function for range>>).Select 
With Selection 
    .Value = "School" 
    .Offset(1,0).Value = "Principal" 
    .Offset(1,0).Font.Bold = True 
    .Offset(4,1).Value = "Student" 
    .Offset(4,1).Font.Bold = True 
    .Offset(4,2).Value = "Student ID" 
    .Offset(4,2).Font.Bold = True 

그래서 내가이 형식이기 때문에 기능을 루핑을 찾고 답. 어떤 종류의 영혼이라도 vba의 개념을 이해하는 데 도움이 될 수 있습니까?

답변

0

매크로를 Sheet1에있는 데이터를 유지하고 실행 ... 작은 오류가 u는 쉽게

col1 = Sheet1.Cells(2, 1) 
prin1 = Sheet1.Cells(2, 2) 
Sheet2.Cells(1, 1) = "School" 
Sheet2.Cells(1, 2) = "Principal" 
Sheet2.Cells(2, 1) = col1 
Sheet2.Cells(2, 2) = prin1 
b = 5 
c = 1 
Sheet2.Cells(b - 1, 1) = "Student" 
Sheet2.Cells(b - 1, 2) = "St ID" 
a = 3 

Do While Sheet1.Cells(a, 1) <> "" 
If col1 = Sheet2.Cells(c + 1, 1) Then 
Sheet2.Cells(b, 1) = Sheet1.Cells(a, 3) 
Sheet2.Cells(b, 2) = Sheet1.Cells(a, 4) 
b = b + 1 
Else 
c = b + 1 
b = c + 3 

col1 = Sheet1.Cells(a, 1) 
prin1 = Sheet1.Cells(a, 2) 
Sheet2.Cells(c, 1) = "School" 
Sheet2.Cells(c, 2) = "Principal" 
Sheet2.Cells(c + 1, 1) = col1 
Sheet2.Cells(c + 1, 2) = prin1 
Sheet2.Cells(b - 1, 1) = "Student" 
Sheet2.Cells(b - 1, 2) = "St ID" 
Sheet2.Cells(b, 1) = Sheet1.Cells(a, 3) 
Sheet2.Cells(b, 2) = Sheet1.Cells(a, 4) 
End If 
a = a + 1 
Loop 
+0

를 해결할 수 그것을 밖으로 작업하는 경우 나 추출하기 위해 노력하고있어 데이터가 정확히로하지 않습니다 .. 내 매크로가 있습니다 보기에 표시된 것. 비슷한 학교의 학생들과 일치하지 않습니까? 너무 이상해. –

관련 문제