Results 1 to 4 of 4

Do Loop with Variable Range

Threaded View

  1. #1
    Registered User
    Join Date
    07-16-2013
    Location
    operation
    MS-Off Ver
    Excel 2010
    Posts
    15

    Do Loop with Variable Range

    The following macro is in a file that I inherited and I would like to change it so that it will stop after reaching the last row of data (blank after that). I am new to Macros and it looks like there is a lot of junk in this macro, but right now I just want to limit it to the data range which changes daily when this is run. Any help is appreciated.
    Sub Subs_insert()
    '
    ' Subs_insert Macro
    '
    
    '
    Dim startLocation As Integer
    startLocation = 2
    endLocation = 225 * 13 + 225
    rowLocation = 3
    
    Do
    
        Windows("Hotlist Template V2_1.xlsm").Activate
        
        Range("B" & startLocation).Select
        Selection.Copy
        Windows("Hotlist V2_0 Tools.XLSX").Activate
        Sheets("Family Tool").Select
        
        Range("B2").Select
        Range("B2").Activate
        
        ActiveSheet.Paste
        Range("C2:C14").Select
        Application.CutCopyMode = False
        Windows("Hotlist Template V2_1.xlsm").Activate
        Windows("Hotlist V2_0 Tools.XLSX").Activate
        Sheets("Family Tool").Select
        Range("C9").Select
        Windows("Hotlist Template V2_1.xlsm").Activate
        Rows(rowLocation).Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("B" & startLocation).Select
        Selection.Copy
        Windows("Hotlist V2_0 Tools.xlsx").Activate
        Sheets("Family Tool").Select
        
        Range("B2").Select
        ActiveSheet.Paste
        Range("C2:AF14").Select
        Application.CutCopyMode = False
        Selection.Copy
        Windows("Hotlist Template V2_1.xlsm").Activate
        Range("B" & startLocation).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
      '  Windows("Hotlist V2_0 Tools.xlsx").Activate
      '  Sheets("Family Tool").Select
        
      '  Range("D2:AF14").Select
      '  Application.CutCopyMode = False
      '  Selection.Copy
      '  Windows("Hotlist Template V2_1.xlsm").Activate
      '  Range("D" & startLocation).Select
      '  Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
      '  Windows("LCD_DSI.XLS").Activate
      '  Application.CutCopyMode = False
        Windows("Hotlist Template V2_1.xlsm").Activate
        
        startLocation = startLocation + 14
        rowLocation = rowLocation + 14
        
    Loop Until startLocation > endLocation
    End Sub
    Last edited by Austex_egger; 07-24-2013 at 03:36 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  2. Referencing variable Range in a loop
    By Samirkc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2006, 07:55 AM
  3. How to reference variable range in a loop
    By Samirkc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-13-2006, 11:15 AM
  4. Setting a range within a loop variable for copy/paste
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-21-2005, 12:10 PM
  5. [SOLVED] Setting a range within a loop variable for copy/paste
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-20-2005, 06:25 PM

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