2016-07-21 2 views
0

열 14에서 끝날 때까지 시작하는 열 K를 통해 루프를 시도합니다. 다음 코드를 작성했지만 Range ("K14 :") 행에서 작동하지 않습니다. Range ("K14"& Rows.Count)를 사용하여 시도했지만 그 중 하나도 도움이되지 않았다.전체 행을 복사하려면 VBA에서 열을 반복하십시오

Windows("Price VolatilityDM.xlsm").Activate 
Sheets("Volatility Static Data").Activate 
Dim x As Single 
Dim Cell As Range 
For Each Cell In Range("K14:") 
    If Cell.Value > 0.25 Then 
     Sheets("Volatility Static Data").Range("B:K").Copy 
     Windows("Tolerance ReportDM.xslm").Activate 
     Sheets("Sheet1").Range("K17:Q17").Paste 
    End If 
Next Cell 
+0

'한 lastrow = 세포 (rows.count, 11) .END (xlup를) lastrow 어둡게 셀에만 범위 ("K에서 각 셀에 대한 14 : K "& lastrow)' – Diogo

+0

OP에는'lastrow '이 없습니다 ... 아직 :) – Dave

답변

2
Windows("Price VolatilityDM.xlsm").Activate 
Sheets("Volatility Static Data").Activate 
Set sh = ThisWorkbook.Workheets("Volatility Static Data") ' add a reference to the sheet for simplicity 
Dim x As Single 
Dim Cell As Range 
Dim lastRow 
lastRow = sh.Cells(sh.Rows.Count, "K").End(xlUp).Row ' get the last row 
For Each Cell In Range("K14:K" & lastRow) 
    If Cell.Value > 0.25 Then 
     Sheets("Volatility Static Data").Range("B:K").Copy 
     Windows("Tolerance ReportDM.xslm").Activate 
     Sheets("Sheet1").Range("K17:Q17").Paste 
    End If 
Next Cell 

당신은 단지 Range 객체의 끝을 찾아 그에게 반복 확인해야합니다. 위 참조; 질문이 있으면 알려주세요.

0

전체 범위 쓰기를 완료하지 않았기 때문에 거기에서 멈 춥니 다. "K14:"은 잘못된 구문입니다. 예를 들어, 당신은 할 수 : "K14:K" & LastRow

0

는 14에서 시작 열 K의 끝을 찾으려면이 같은 것을 사용할 수 있습니다

dim end as range 
set cell = range("K14") 

'go down one cell at a time until you find that 
'the next one is empty. This is the end of the column 

do while not cell.offset(1,0).value = "" 

    set cell = cell.offset(1,0) 
loop 
set end = cell 

을 한 후이 좋겠 코드에서 for each cell in range("K14:" & end.address)

를 사용 다음과 같이 :

Windows("Price VolatilityDM.xlsm").Activate 
Sheets("Volatility Static Data").Activate 
Dim x As Single 
Dim Cell As Range 
dim end as range 

set cell = range("K14") 
'go down one cell at a time until you find that 
'the next one is empty. This is the end of the column 

do while not cell.offset(1,0).value = "" 
    set cell = cell.offset(1,0) 
loop 
set end = cell 
For Each Cell In Range("K14:" & end.address) 
    If Cell.Value > 0.25 Then 
     Sheets("Volatility Static Data").Range("B:K").Copy 
     Windows("Tolerance ReportDM.xslm").Activate 
     Sheets("Sheet1").Range("K17:Q17").Paste 
    End If 
Next Cell 
관련 문제