이것은 솔직히 말해서 내 기술 세트를 뛰어 넘었습니다. 나는 이런 식으로 한 번도 해 본 적이 없으며 가능한지 모르겠습니다. 아래 절차에서는 B6 열의 값을 기반으로 배열을 만듭니다.어레이의 값을 액세스하고 콤보 상자에 표시
Private Sub dsbPositionBoard_Startup() Handles Me.Startup
'This event runs when the dsbPositionBoard starts. The procedure
'checks for the values in column A of the allPositionsAnualized sheet
'and populates the combobox with those values. If there are no values the box
'is disabled.
Dim xlRng As Excel.Range
Dim strRngArr As String
Dim strChkRange As String
Try
xlWB = CType(Globals.ThisWorkbook.Application.ActiveWorkbook, Excel.Workbook)
xlWS = DirectCast(xlWB.Sheets("allPositionsAnnualized"), Excel.Worksheet)
xlRng = DirectCast(xlWS.Range("B6", xlWS.Range("B6").End(Excel.XlDirection.xlDown)), Excel.Range)
strRngArr = String.Empty
strChkRange = CStr(xlWS.Range("B6").Value)
If (String.IsNullOrEmpty(strChkRange)) Then
cmbSelectPosition.Enabled = False
Else
'Build a string array delimited by commas
For i As Integer = 1 To xlRng.Rows.Count
Dim xlRngCell As Excel.Range = DirectCast(xlRng.Rows(i), Excel.Range)
strRngArr &= DirectCast(xlRngCell.Value.ToString, String) & ","
Next
strRngArr = strRngArr.Remove(strRngArr.Length - 1, 1)
cmbSelectPosition.Items.AddRange(strRngArr.Split(","c))
xlRng = Nothing
xlWS = Nothing
End If
Catch ex As Exception
MsgBox("There no positions available to select", CType(vbOKOnly, MsgBoxStyle), "Empty Selection")
End Try
End Sub
이제 아래 함수는 셀 범위의 값을 선택 헬퍼 세포 (B37)에 전달하고 대응하는 시트를 선택하는 데 사용된다. 이 함수가 도우미 셀에 전달하는 값은 위 배열의 값과 같습니다.
Private Function MoveBtwSheets(range As String) As String
'This function is used to toggle between the position board
'and the employee board. The function is utilized to select
'the employees listed in the position board, click on the radio button
' and open that employees information in the employee board
'@parameter range: Selects the cell with the employee name
Dim xlCalc As Excel.Worksheet
strMessage = "This employee does not exist. Please verify the employee name"
strCaption = "Selection Error"
msgBoxType = MessageBoxIcon.Error
msgBoxBtns = MessageBoxButtons.OK
xlWB = CType(Globals.ThisWorkbook.Application.ActiveWorkbook, Excel.Workbook)
xlCalc = CType(xlWB.Worksheets("calculationSheets"), Excel.Worksheet)
xlWSEE = CType(xlWB.Worksheets("employeeBoard"), Excel.Worksheet)
xlWSPOS = CType(xlWB.Worksheets("positionBoard"), Excel.Worksheet)
Application.ScreenUpdating = False
Try
xlCalc.Range("B36").Value = xlWSPOS.Range(range).Value
With xlWSEE
.Select()
.Range("E37").Select()
End With
Application.ScreenUpdating = True
Catch ex As Exception
MessageBox.Show(strMessage, strCaption, msgBoxBtns, msgBoxType)
End Try
Return ""
End Function
그래서 내가 기능을 추가하고 싶었던 것을 B37의 값에 대한 내 배열을 검색 한 후 첫 번째 절차에 콤보 상자에 그 값을 표시하는 방법입니다. 기본적으로 배열 대신 항목을 선택하는 대신 함수가 배열을 검색하여 해당 항목을 선택합니다.
매우 명확하지 않은 경우 스크린 샷을 명확히하거나 게시 할 수 있습니다.
다른 질문과 마찬가지로 스크린 샷과 간단한 예를 게시하는 것이 좋습니다. 보시다시피 아이디어가 명확하게 전달되면 도움이 신속하게 제공됩니다. – varocarbas
@varocarbas, 나는 스크린 샷을 준비하고 게시 할 것이다. 감사합니다 –
우수! 감사. – varocarbas