2017-12-24 33 views
0

Excel의 특정 시트에 쓰려고하는 두 배의 배열이 있습니다.시트에 사용 된 데이터의 마지막 열에 범위 삽입

이 시트에는 이미 데이터가 있습니다. 밖에 사용 된 데이터의 마지막 열을 찾는 방법을 보여 주며 열의 NUMBER를 반환하는 코드 스 니펫이 많이 있습니다. 하지만 문자열로 문자를 필요로 범위 함수를 사용하여 내 배열에 데이터를 쓰려고합니다. 이 작업을 수행하는 더 좋은 방법이 있습니까?

가 여기에 지금까지 내 코드입니다 :

Dim lCol As Integer 
     With GlobVars.Wksht 
      lCol = .Cells(1, .Columns.Count).End(Excel.XlDirection.xlToLeft).Column 
     End With 
     lCol += 1 
     GlobVars.Wksht.Range("I need something in these parentheses that will relate the lcol value and whatever row I want to put it in").Value = deltaxyarr 'copies the deltaxyarr as a range into the current active worksheet (data reduction) 
+0

이 코드는 실제로 VB.NET입니까? A .NET'Long'이 잘못되었습니다. – Plutonix

+0

10 진수 형식이므로 내 데이터 형식으로 long을 선택했습니다. 복사 할 어레이의 데이터 유형을 Excel로 변경하지만 데이터의 다음 사용하지 않는 열의 범위에 쓰는 방법에 대한 구문에 진정으로 더 많은 관심이 있습니다. @Plutonix 편집 : 변경할 수 있습니다. Decimal로하지만 그것은 정말로 내가 원하는 것에 대해 변경하지 않을 것입니다. :) –

+0

롱은 정수 타입입니다 - 십진수는 없습니다. > 9,000000000000000000이 열 개수보다 훨씬 클 수 있습니다. – Plutonix

답변

0

워크 시트 배열을 전송하려면 배열의 크기와 같은 범위의 크기가 있어야합니다. 그것을하기 위해, 당신은 편리한 Resize 속성을 사용할 수 있습니다. 여기에 사물이 작동하는 방법은 다음과 같습니다

Sub TransferArray() 

    Dim arr As Variant 

    'Copy range into array. 
    'This array is 1) always 2-dimensional and 2) its lower bound is always 1. 
    arr = Range("A1:F10") 

    'To transer array, the receiving range should accomodate array fully. 
    'To do it, we can use Resize property. 
    'This means, all we need is to choose top left cell of our receiving range. 
    'Here K1 cell is this very cell. 
    'The RowSize argument means how many rows we should expand down, 
    'and ColumnSize - how many column we should expand right. 
    'Apparently, these numbers are upper bound of 1-st dimension 
    'and upper bound of 2-nd dimension, respectively. 
    Range("K1").Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr 

End Sub 
+0

안녕하세요 JohnyL 회신 해줘서 고마워. 시트에 배열을 배치 할 정확한 위치를 찾으려고합니다. 예를 들어 excel에서 A1 : C5와 거리가 먼 데이터 (항상 5x3 배열)가 있다고 가정 해 보겠습니다. D1에서 시작하는 첫 번째 데이터 세트 바로 다음에 넣으려는 또 다른 배열이 있지만 다음에 사용되지 않는 열을 찾을 코드 줄이 필요합니다. 그런 다음이 코드 줄이 작동하는 방식으로 사용하지 않는 열을 넣을 코드 줄이 필요합니다. {범위 ("시작 셀 D1 여기"). 크기 조정 (UBound (arr, 1), UBound arr, 2)). 값 = arr} –

0

감사의 내가 Cells.Address 멤버를 사용하여 작업하는 몇 가지 코드를 얻을 수 있었다 Qharr 할 수 있습니다. 다음은 작업중인 코드 조각입니다.

  lCol = .Cells(1, .Columns.Count).End(Excel.XlDirection.xlToLeft).Column 

      lCol += 1 
      GlobVars.Wksht.Range(GlobVars.Wksht.Cells(1, lCol).Address).Resize(UBound(deltaxyarr, 1), UBound(deltaxyarr, 2)).Value = deltaxyarr