2014-01-31 2 views
0

코드 뒤에 아이디어는 고객 이름을 찾은 다음 일년 내내 판매 수준을 찾아이 모든 데이터를 다른 시트에 붙여 넣어야한다는 아이디어입니다.워크 시트 ("xyz") 쿼리의 각 셀에 대해

런타임 오류 '1004'받기 다음 줄에서 응용 프로그램 정의 또는 개체 정의 오류가 발생했습니다. 오류가 발생하는 곳을 별표 표시했습니다.

Sub Import_CustomerData() 

Dim strMonth As String 
Dim rngMonth As Range 

Dim DataImportColum As Integer 
Dim DataImportRow As Integer 

Dim strFirstCustomer As String 
Dim strSecondCustomer As String 
Dim strThirdCustomer As String 
Dim strFourthCustomer As String 
Dim strFifthCustomer As String 

Dim lngFirstCustomerSales As Long 
Dim lngSecondCustomerSales As Long 
Dim lngThirdCustomerSales As Long 
Dim lngFourthCustomerSales As Long 
Dim lngFifthCustomerSales As Long 
Dim lngTotalSales As Long 

Dim cell As Range 
Dim x As Integer 

'Finding Data for clients 
For Each cell In Worksheets("Data entry").Range("A1:A99") 

If cell.Value = "Customer Sales" Then 

    strFirstCustomer = cell.Offset(1, 0).Value 
    strSecondCustomer = cell.Offset(2, 0).Value 
    strThirdCustomer = cell.Offset(3, 0).Value 
    strFourthCustomer = cell.Offset(4, 0).Value 
    strFifthCustomer = cell.Offset(5, 0).Value 

End If 

Next 

'Extracting Data from Customer sheet 

***For Each cell In Worksheets("Client_Customer").Range("B83:86")*** 

'First Customer 
If cell.Value = strFirstCustomer Then 
    lngFirstCustomerSales = Val(cell.Offset(0, 1)) 
End If 

'Second Customer 
If cell.Value = strSecondCustomer Then 
    lngSecondCustomerSales = Val(cell.Offset(0, 1)) 
End If 

'Third Customer 
If cell.Value = strThirdCustomer Then 
    lngThirdCustomerSales = Val(cell.Offset(0, 1)) 
End If 

'Fourth Customer 
If cell.Value = strFourthCustomer Then 
    lngFourthCustomerSales = Val(cell.Offset(0, 1)) 
End If 

'Fifth Customer 
If cell.Value = gxdfg Then 
    lngFifthCustomerSales = Val(cell.Offset(0, 1)) 
End If 

'Total Customers Sales 
If cell.Value = "Total:" Then 
    lngTotalSales = Val(cell.Offset(0, 1)) 
End If 

Next 

'Importing it into Data Customer Monthly 2013 sheet. 

'Determing month of client system reports 
    strMonth = Sheets("Client_Customer").Range("B8").Value 

If strMonth = "" Then 

    frmEnter_month.Show 

Else 

    iLenMonth = Len(strMonth) 
     x = iLenMonth - 5 
      strLeftMonth = Left(strMonth, x) 

End If 

'To find Column of Customer imput 
For Each cell In Range("B4:M4") 

     If cell.Value = strLeftMonth Then 
      DataImportColumn = cell.Column 

     End If 

Next 

For Each cell In Worksheets("data customer monthly 2013").Range("A3:A9999") 

'First Customer 
If cell.Value = strFirstCustomer Then 
     DataImportRow = cell.Row 

** 2 ** lngFirstCustomerSales = Cells(DataImportRow, DataImportColumn).Offset(0, 2).Value ** 2 ** 
End If 

'Second Customer 
If cell.Value = strSecondCustomer Then 
     DataImportRow = cell.Row 

     lngSecondCustomerSales = Cells(DataImportRow, DataImportColumn).Offset(0, 2).Value 
End If 

'Third Customer 
If cell.Value = strThirdCustomer Then 
     DataImportRow = cell.Row 

     lngThirdCustomerSales = Cells(DataImportRow, DataImportColumn).Offset(0, 2).Value 
End If 

'Fourth customer 
If cell.Value = strFourthCustomer Then 
     DataImportRow = cell.Row 

    lngFourthCustomerSales = Cells(DataImportRow, DataImportColumn).Offset(0, 2).Value 
End If 

'Fifth Customer 
If cell.Value = strFifthCustomer Then 
     DataImportRow = cell.Row 

    lngFifthCustomerSales = Cells(DataImportRow, DataImportColumn).Offset(0, 2).Value 
End If 

'Total Sales 
If cell.Value = "Total Sales" Then 
     DataImportRow = cell.Row 

    lngTotalSales = Cells(48, DataImportColumn).Value 
End If 

Next 

DeleteClientSheets 

End Sub 

많은 양의 코드를 사용하여 죄송합니다. 누구든지 제안 사항이 있으십니까? 셀이 범위로 정의 되었기 때문에 질문을 설명하는 데 도움이되는 다른 것을 찾을 수 없습니다.

EDIT1 :

두 번째 질문 : Silenxor의 확실한 해결책 후, 나는 다음과 같은 표시와 함께 라인에 코드를 얻고있다 : ** 2 **

내가 점점 오전 오류는 처음과 동일 오류. 당신의 별표 라인에 관해서

답변

0

For Each cell In Worksheets("Client_Customer").Range("B83:86") 

는 정말 간단한 것이 었습니다

For Each cell In Worksheets("Client_Customer").Range("B83:B86") 
+0

보십시오. 그 Silenxor에 감사드립니다! 하지만 지금은 또 다른 질문이 있습니다. 위의 게시물에서 EDIT1을 참조하십시오. – s0up2up

+0

오류의 세부 사항을 게시 할 수 있습니까? 아마도 그것은 Cells (DataImportRow, DataImportColumn)의 내용 일 수 있습니다. 오프셋 (0, 2)은 숫자가 아니십니까? 당신은 그것의 값을 long 타입의 변수에 저장하려고 시도하고있다. – Silenxor

+0

또 다른 것은 당신이 원하는 것은 DataImportRow와 DataAImportColumn이 매크로의 어떤 지점에 있는지를 검사하는 것이다. 사실 이러한 변수 중 하나가 0이면 셀 (0, 0) – Silenxor

관련 문제