incrementing in a Macro

trunkmonkey

New Member
Joined
Jul 7, 2011
Messages
2
Hello,
I am trying to increment in a macro, for a period set in a for loop. I need the macro to retrieve data from one sheet and paste it in another use solver and past the results in the original sheet. The code that I have so far is as follows:

Sub take4()
'
' take4 Macro
'

'
Sheets("switchgrass results").Select
For x = 115 To 162
Range("A115:C115").Select
Selection.Copy
ActiveCell.Offset(1, 0).Select
Sheets("Switchgrass model").Select
Range("R88:T88").Select
ActiveSheet.Paste
SolverOk SetCell:="$AB$96", MaxMinVal:=2, ValueOf:=0, ByChange:= _
"$B$126:$AA$126", Engine:=2, EngineDesc:="Simplex LP"
SolverSolve
ActiveWindow.ScrollColumn = 24
Range("AF96:AH96").Select
Selection.Copy
Sheets("switchgrass results").Select
Range("D115:F115").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveCell.Offset(1, 0).Select
Sheets("Switchgrass model").Select
Next x
End Sub

Any help would be greatly appreciated
Thanks!

P.S. if you suggest that I don't use a for loop and just have it run until an empty cell, I can do that as well.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Welcome to the board.

Dunno if I can do this blind, but maybe ...

Code:
Sub take4()
    Dim wksMod      As Worksheet
    Dim wksRes      As Worksheet
    Dim iRow        As Long
 
    Set wksMod = Worksheets("Switchgrass model")
    Set wksRes = Worksheets("Switchgrass results")
    wksMod.Select
    
    SolverReset
    SolverOk SetCell:="AB96", _
             MaxMinVal:=2, _
             ValueOf:=0, _
             ByChange:="B126:AA126", _
             Engine:=2, _
             EngineDesc:="Simplex LP"

    For iRow = 115 To 162
        wksRes.Cells(iRow, "A").Range("A1:C1").Copy Range("R88")
        SolverSolve
        wksRes.Cells(iRow, "D").Range("A1:C1").Value = Range("AF96:AH96").Value
    Next iRow
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top