I can't get excel to do what I want after creating this VBA script:
Sub sbCopyRangeToAnotherSheet()
LastColumn = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Columns
For n = 63 To 63
For i = n To n
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(i, 45), Cells(i + 6, 54)).Copy
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(63, 64), Cells(69, 74)).PasteSpecial xlPasteAll
RunPhreeqc
Worksheets("Output").Activate
Worksheets("Output").Range(Cells(2, 20), Cells(8, 29)).Copy
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(i + 10, 45), Cells(i + 16, 54)).PasteSpecial xlPasteAll
Next i
'Application.ScreenUpdating = True
Next n
For i = n + 20 To 103
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(i, 45), Cells(i + 6, 54)).Copy
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(63, 64), Cells(69, 74)).PasteSpecial xlPasteAll
RunPhreeqc
Worksheets("Output").Activate
Worksheets("Output").Range(Cells(2, 20), Cells(8, 29)).Copy
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(i + 10, 45), Cells(i + 16, 54)).PasteSpecial xlPasteAll
Next i
End Sub
What I am trying to do here is copy data from 'Data' sheet and paste it to the same 'Data' sheet. Then I run IPhreeqc, and copy and paste the output from the 'Output' sheet back into the 'Data' sheet. The problem here is that VBA is not highlighting the range of cells I want, it just highlights the range of cells a row down. Many thanks in advance.
Sub sbCopyRangeToAnotherSheet()
LastColumn = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Columns
For n = 63 To 63
For i = n To n
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(i, 45), Cells(i + 6, 54)).Copy
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(63, 64), Cells(69, 74)).PasteSpecial xlPasteAll
RunPhreeqc
Worksheets("Output").Activate
Worksheets("Output").Range(Cells(2, 20), Cells(8, 29)).Copy
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(i + 10, 45), Cells(i + 16, 54)).PasteSpecial xlPasteAll
Next i
'Application.ScreenUpdating = True
Next n
For i = n + 20 To 103
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(i, 45), Cells(i + 6, 54)).Copy
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(63, 64), Cells(69, 74)).PasteSpecial xlPasteAll
RunPhreeqc
Worksheets("Output").Activate
Worksheets("Output").Range(Cells(2, 20), Cells(8, 29)).Copy
Worksheets("Data").Activate
Worksheets("Data").Range(Cells(i + 10, 45), Cells(i + 16, 54)).PasteSpecial xlPasteAll
Next i
End Sub
What I am trying to do here is copy data from 'Data' sheet and paste it to the same 'Data' sheet. Then I run IPhreeqc, and copy and paste the output from the 'Output' sheet back into the 'Data' sheet. The problem here is that VBA is not highlighting the range of cells I want, it just highlights the range of cells a row down. Many thanks in advance.
Last edited: