Вопрос

enter image description here

I have two ranges as below

Dim onedl, twodl As Range
Dim lastrow as long

Set oned1 = xl.ThisWorkbook.Sheets(1).Range("C5:C" & lastrow)
Set twod1 = xl.ThisWorkbook.Sheets(1).Range("F5:F" & lastrow)
lastrow = xl.ThisWorkbook.Sheets(1).Cells(Rows.Count, 2).End(xlUp).Row

Can I subtract the two ranges and compute the value from Range("I5:I" & lastrow), something like (twod1 - oned1) to be populated.

Это было полезно?

Решение

With something that simple you could just write =F5-C5 and drag, but VBA:

Range("I5").FormulaR1C1 = "=IF(RC[-3]="""","""",RC[-3]-RC[-6])"
Range("I5").AutoFill Destination:=Range("I5:I" & lastrow), Type:=xlFillDefault

Also, your "lastrow" declaration should come first in that or it won't know what "lastrow" is.

EDIT: This completely ignores the fact that you're trying to set up arrays (if that's what you're trying to do). Let me know if this isn't what you're looking for, I suppose.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top