Results 1 to 18 of 18

Macro copy one row at a time

Threaded View

  1. #1
    Registered User
    Join Date
    01-05-2011
    Location
    Slovenia
    MS-Off Ver
    Excel 2016
    Posts
    49

    Question Macro copy one row at a time

    Hi to all

    I'm new with vba programming so let me explain what's my problem. I would really appreciate if someone can help me.
    I have many combinations located in spreadsheet ''COMB'' in cell from b1:f1 in 792 rows. I would like to copy each row at a time to the spreadsheets ''WGP'' in cell from b4:b8 and then run my existing macro which run excel solver and then copy results to the b48 and bellow

    All I need is a code that will automatically copy one row at a time, run solver and copy results to another location and then copy next row and so on till end of a list of rows


    I attach my excel file and existing macros which was run manual by button, but now I want to automatic run all by some kind of a loop.
    Thanks in advance. Josef


    Excel solver code
    Private Sub CommandButton2_Click()
    SolverOk SetCell:="$K$3", MaxMinVal:=2, ValueOf:=0, ByChange:="$I$4:$I$8", _
            Engine:=1, EngineDesc:="GRG Nonlinear"
        SolverOk SetCell:="$K$3", MaxMinVal:=2, ValueOf:=0, ByChange:="$I$4:$I$8", _
            Engine:=1, EngineDesc:="GRG Nonlinear"
        SolverSolve
    End Sub
    copy in two row based on number of scenario
    Private Sub CommandButton3_Click()
    stc = Excel.Range("I2").Value
        
        Range("B4:B8").Select
        Selection.Copy
        Range("B47").Select
        ActiveCell.Offset(stc, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=True
        Range("B48").Select
        
    Range("I4:I8").Select
        Selection.Copy
        Range("A48").Select
        ActiveCell.Offset(stc, 1).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=True
        Range("A49").Select
        
      Range("c14:c18").Select
        Selection.Copy
        Range("f48").Select
        ActiveCell.Offset(stc, 1).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=True
        Range("f49").Select
    End Sub
    now i have a button which move manualy to the next scenario number

    Dim intDV As Integer
    Dim ws As Worksheet
    Dim c As Range
    Dim rngList As Range
    
    Set ws = Sheets("WGP")
    Set c = ws.Range("I2")
    Set rngList = ws.Range("STEVILA ")
    intDV = 0
    On Error Resume Next
    intDV = Application.WorksheetFunction.Match(c.Value, rngList, 0)
    
    If intDV = 0 Or intDV = 1 Then
      c.Value = rngList.Cells(rngList.Rows.Count, 1)
    Else
      c.Value = rngList.Cells(intDV - 1, 1)
    End If
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Sequential copy/pastes in macro take too much time
    By macaonghus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-27-2014, 05:08 PM
  2. macro which uses two worksheets at a time (copy and paste)
    By Manjula1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2014, 07:23 AM
  3. Macro to copy and paste at specific time of day
    By BCrawford in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-30-2013, 06:27 AM
  4. Macro to Copy Workbook from One Drive to another at a Specific Time
    By ashishmac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-09-2013, 02:28 AM
  5. [SOLVED] macro error Copy Time format to other Worksheet and continues copy range
    By feroguz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-25-2012, 01:30 PM
  6. macro to copy to new column each time used
    By deanomcbeano27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-06-2009, 05:51 PM
  7. i would like a macro to copy x time rows based
    By dversa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2009, 08:52 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1