+ Reply to Thread
Results 1 to 2 of 2

Insert every other row selection and copy into existing macro

  1. #1
    Registered User
    Join Date
    07-20-2015
    Location
    australia
    MS-Off Ver
    7
    Posts
    2

    Insert every other row selection and copy into existing macro

    Hi guys,

    I appreciate the help with this guys... I'm such a noob. So i borrowed the following script for selecting every other row from a free tutorial site somewhere on the web...

    Sub EveryOtherRow()
    Dim rng As Range
    Dim InputRng As Range
    Dim OutRng As Range
    Dim xInterval As Integer
    xTitleId = "KutoolsforExcel"
    Set InputRng = Application.Selection
    Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
    xInterval = Application.InputBox("Enter row interval", xTitleId, Type:=1)
    For i = 1 To InputRng.Rows.Count Step xInterval + 1
    Set rng = InputRng.Cells(i, 1)
    If OutRng Is Nothing Then
    Set OutRng = rng
    Else
    Set OutRng = Application.Union(OutRng, rng)
    End If
    Next
    OutRng.EntireRow.Select

    Which I used while recording a macro designed to extract behavioural data from psychophysiological experiments. While recording and running the above script, two dialogue boxes appeared to nominate the parameters of the selections. First the range (which i had previously selected and so was automatically recorded in this dialogue box) and then the row interval for selections (in this case: 1 as I wish to highlight every other row). The resulting selected rows were copied and then pasted into a new sheet in order to have the selected data be formatted without cells in between each data point. The reason for doing this way, is for formatting in a third sheet and for preservation of the raw data formatting.

    However, when I run the finished macro the above script is missing. So my question is, how can I insert this into my macro in VBA with the parameters that meet the range selection 'A2:A400' and with a selection interval of one (i.e. select A2, A4, A6 etc.), have these selections copied and pasted to a new sheet?

    Thanks again to anyone who can help, the macro took me a fair while to record and editing useless code took almost as long. I appreciate it guys.

    Cheers,

    Matt.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Insert every other row selection and copy into existing macro

    This copies every other row in range A2:A400 to a new worksheet.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to insert a row below ActiveCell, copy row down, and add 'v1' to the existing number
    By jamesywilkinson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-22-2013, 10:50 AM
  2. Replies: 11
    Last Post: 11-04-2013, 04:32 PM
  3. Replies: 3
    Last Post: 10-14-2013, 03:06 PM
  4. [SOLVED] Adding additional selection criteria to existing Macro
    By Mogpot1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2013, 10:29 AM
  5. Copy Selection and Paste using Insert
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-24-2013, 07:09 AM
  6. Trying to get an existing pivot to change pivotfields based on a selection via macro
    By livernut in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2013, 07:21 AM
  7. [SOLVED] Copy Column as Selection and Insert to the next Empty Column MACRO
    By kaurka in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-22-2013, 12:50 PM
  8. [SOLVED] On selection, find dups in two colums across workbook, copy duplicates to existing sheet.
    By Joshuarat in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-21-2012, 07:54 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