Greetings all people human and otherwise. I've got a question regarding copying a range of information from one worksheet to another with a piece of VBA code. I have a macro that does some data manipulation, and an excel sheet that updates as required to show those manipulations. The manipulations are a little lengthy, and I'm not including them since they are essentially mathematical operations. The mathematical operations are iterative in nature, and I am using a for loop to enable the expressions to converge to a solution. The issue I have is that I want to output specific results of the mathematical operations at every iteration of the for loop, and review to make sure that it is behaving correctly. Please see below.
As it can be seen, I am basically wanting to transfer the values of a select range to a specific sheet labeled "Output". The above code works, and does what I need it to do, but it is not very flexible in conjunction with my for loop. That being said, I am looking for the syntax (or alternative approach) to transfer the information from the same range on the "MathStuff" worksheet that will change with the for loop as appropriate, but I want the flexibility to shift the range on the 'Output" sheet. Please see below.
This code gives me an error when I run it, probably due to my syntax (I think). The variable "i" is essentially a form of counter that, every time the math expressions are looped, the values shift down in the "Output" sheet, thus not overwriting the previously 'pasted' values. The result is that there are multiple sets of results that are reflected of the number of iterations of the "MathStuff" sheet went through to converge to a solution. I believe I am getting hung up on the syntax primarily, but I would appreciate any feedback. And thanks ahead of time for reading my small novel.
Code:
Worksheets("Output").Range("A1:J176").Value = Worksheets("MathStuff").Range("A120:J296").Value
As it can be seen, I am basically wanting to transfer the values of a select range to a specific sheet labeled "Output". The above code works, and does what I need it to do, but it is not very flexible in conjunction with my for loop. That being said, I am looking for the syntax (or alternative approach) to transfer the information from the same range on the "MathStuff" worksheet that will change with the for loop as appropriate, but I want the flexibility to shift the range on the 'Output" sheet. Please see below.
Code:
Worksheets("Output").Range(Cells(1,1 + i),Cells(10,176 + i)).Value = Worksheets("MathStuff").Range("A120:J296").Value
This code gives me an error when I run it, probably due to my syntax (I think). The variable "i" is essentially a form of counter that, every time the math expressions are looped, the values shift down in the "Output" sheet, thus not overwriting the previously 'pasted' values. The result is that there are multiple sets of results that are reflected of the number of iterations of the "MathStuff" sheet went through to converge to a solution. I believe I am getting hung up on the syntax primarily, but I would appreciate any feedback. And thanks ahead of time for reading my small novel.