Hi there,
I'm pulling data from FTP files and using that data to calculate a monetary balance. The FTP file has some blank cells and the xlUp function gets stuck... it doesn't really cause a problem but I would prefer to select the first cell in the sheet and find the range by using xlDown, rather than selecting the last cell and using ulUp. When I attempt to input the lastRow variable into a cell using the .Formula method, it selects the first row. What's going on with my code here?
The resulting formula looks like this: =SUMIF('Positions'!G2:G2,"<>USD",'Positions'!J2:J2)" ...obviously not what I want. I want it to select the range in Columns G and J and not just the first cell of the range.
I'm pulling data from FTP files and using that data to calculate a monetary balance. The FTP file has some blank cells and the xlUp function gets stuck... it doesn't really cause a problem but I would prefer to select the first cell in the sheet and find the range by using xlDown, rather than selecting the last cell and using ulUp. When I attempt to input the lastRow variable into a cell using the .Formula method, it selects the first row. What's going on with my code here?
Code:
Sub BalanceCheck()
Dim lastRow As Integer
lastRow = Range("A1").End(xlDown).Row
Dim CCYbalance As Range
Set CCYbalance = Sheets("Balances").Range("B4")
CCYbalance.Formula = "=SUMIF('Positions'!G2:G" & lastRow & _
",""<>USD""," & "'Positions'!J2:J" & lastRow & ")"
The resulting formula looks like this: =SUMIF('Positions'!G2:G2,"<>USD",'Positions'!J2:J2)" ...obviously not what I want. I want it to select the range in Columns G and J and not just the first cell of the range.