Идея, лежащая в основе кода, заключается в том, что предполагается найти имена клиентов, а затем найти уровень продаж для них в течение года, а затем вставить все эти данные в другой лист.Для каждой ячейки в листах («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 **
Ошибка я получаю то же самое, как первый ошибка.
Это действительно так просто. Спасибо за это Silenxor! Но теперь у меня есть другой вопрос. См. EDIT1 в вышеприведенном сообщении. – s0up2up
Можете ли вы сообщить подробности об ошибке? Может быть, это содержимое Cells (DataImportRow, DataImportColumn). Офсет (0, 2) не является числом? Вы пытаетесь сохранить его значение в переменной типа long – Silenxor
Другая вещь, которую вы можете попробовать, - проверить, какие значения DataImportRow и DataAImportColumn действительно находятся в точке макроса, потому что, глядя на код, оператор if может не выполняться true, в этом случае, если любая из этих переменных равна 0, это будет ошибкой, потому что вы не можете выбрать ячейку (0, 0) – Silenxor