Paste variables in a repeated cell pattern in Excel
Posted: 28 Mar 2019, 05:04
Hi there!
I want to paste a variable multiple times in the first (3) rows of Excel. The vars are obtained by a function
It should look like this. The code I'm using to try to achieve this is the following but it isn't working correctly atm.
The thing I'm trying to do here is select cell 'A1' and paste the 'var'. This works but after this, it doesn't work anymore.
Then go to the cell below and paste the 'var' again. Repeat this one more time and paste the 'var' in cell 'A3'.
The next var should be placed in cell 'B1' again and the 2 'vars' after in cells 'B2' and 'B3'.
I added the 'Trigger' variable so the if function knows when to go to the next column. So after every 3rd 'var' placement, the column should go 1 to the right and the row should go 2 up (that is what I'm trying to do in the 'else' part of the if-statement).
Any help is appreciated!
***EDIT***
I think the Xl.Range("A1").Value := Var should be outside the loop bcs otherwise it would keep resetting the active cell to 'A1'...
I want to paste a variable multiple times in the first (3) rows of Excel. The vars are obtained by a function
It should look like this. The code I'm using to try to achieve this is the following but it isn't working correctly atm.
Code: Select all
Var:=1
Myfunc(2)
Myfunc(2)
Myfunc(1)
MyFunc(var){
Trigger:=var
}
loop 5{
Xl := ComObjActive("Excel.Application")
Xl.Range("A1").Value := Var
if (trigger!=1){
Xl.ActiveCell.Offset(A_Index, A_Index=0).Value := Var
} else {
Xl.ActiveCell.Offset(A_Index-2, A_Index).Value := Var
}
}
Then go to the cell below and paste the 'var' again. Repeat this one more time and paste the 'var' in cell 'A3'.
The next var should be placed in cell 'B1' again and the 2 'vars' after in cells 'B2' and 'B3'.
I added the 'Trigger' variable so the if function knows when to go to the next column. So after every 3rd 'var' placement, the column should go 1 to the right and the row should go 2 up (that is what I'm trying to do in the 'else' part of the if-statement).
Any help is appreciated!
***EDIT***
I think the Xl.Range("A1").Value := Var should be outside the loop bcs otherwise it would keep resetting the active cell to 'A1'...