Почему моя функция гистограммы не работает? - PullRequest
0 голосов
/ 27 сентября 2019

Мне нужно создать гистограмму с помощью кнопки, насколько я знаю, большая часть кода верна, но что-то не так.Это ссылка на файл: https://drive.google.com/file/d/14S4zNl32ZE9qPxETkHabIpDt-9biM87u/view?usp=sharing Я рекомендую использовать файл, чтобы проверить мою ошибку, поскольку она связана с несколькими листами.Цель состоит в том, чтобы кнопка на рабочем листе «Панель инструментов» работала.Спасибо заранее!

Sub CreateHistogram()
Dim inp, outp, bin As Range
Dim kol As String
Dim wd, wh, wdpe As Worksheet

'declare needed worksheets
Set wd = ThisWorkbook.Worksheets("DashBoard")
Set wh = ThisWorkbook.Worksheets("Histogram")
Set wdpe = ThisWorkbook.Worksheets("DataPerStage")

'get stage from dashboard
Stage = wd.Range("H5").Value
'Check here if the stage number is valid, if not: give a MsgBox and stop 
the procedure
v = wd.Cells(5, 8)
If v < 1 Or v > 25 Or v <> Int(v) Or Not IsNumeric(v) Then
    MsgBox ("Not valid")
    Exit Sub
    End If


'remove previous charts and data
Do While wh.ChartObjects.Count > 0
    wh.ChartObjects(1).Delete
Loop
wh.Range("K6:L27").Clear 'Hier comes the output data of the histogram
wh.Range("A:A").Clear

'get data from the indicated stage, and paste it to the worksheet 
"Histogram" column A.
kol = Split(wdpe.Cells(1, Stage).Address, "$")(1) 'Determine the column 
name of the indicated stage
'Now that you know the column name, copy the entire column from 
"DataPerStage" and paste it to "Histogram" column A


With wdpe
    LastRow = .Cells(.Rows.Count, v).End(xlUp).Row
      End With


For i = 1 To LastRow
    wh.Cells(i, 1) = wdpe.Cells(i, v)
Next i

Min = WorksheetFunction.Min(wh.Range("A2:A292" & LastRow))
 Max = WorksheetFunction.Max(wh.Range("A2:A" & LastRow))
'determine the bin size, based on the minimum and maximum, ensure that the correct bin intervals are noted is the range "E7;E26"
For i = 0 To 19
wh.Cells(7 + i, 4) = ((Max - Min) / 19) * i + Min
Next i

'the code line below creates the histogram: Ensure that the data of 
the stage is in column A, and the binrange is in "E7:E26"
Application.Run "ATPVBAEN.XLAM!Histogram", ActiveSheet.Range("$A$2:$A$" & 
wh.Range("A1").End(xlDown).Row), ActiveSheet.Range("K6"), 
ActiveSheet.Range("E7:E26"), False, False, True, False
End Sub

Я думаю, что это как-то связано с диапазонами.Так как я не имею опыта работы с VBA, я ценю любую помощь!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...