Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6654109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:21:02+00:00 2026-05-26T01:21:02+00:00

I have a document that I’m going to hand out to users with three

  • 0

I have a document that I’m going to hand out to users with three non-contiguous groups of arbitrary numbers of rows (same number of columns across the board) depending on their individual needs.
My current macro is quite slow to run, so I was wondering if someone can suggest a better solution than what I have here, or at least point me in the direction of what built in functions may help what I’m doing.

In the script below, I have it set to act on the data in rows: 6, 8-19, 21-60, 63-81.

All this is meant to be doing is deleting the values in the first column of data (sFirstCol = “D”), and shifting values from all columns (E->AC) in the applicable rows one cell to the left, leaving the rightmost column values blank.

Sub RollOver1()
    Dim sFirstCol As String
    Dim sSecCol As String
    Dim sSLastCol As String
    Dim sLastCol As String
    Dim iFirstRow As Integer
    Dim iLastRow As Integer
    Dim excludeRows() As Variant

    sFirstCol = "D"
    sSecCol = "E"
    sSLastCol = "AB"
    sLastCol = "AC"
    iFirstRow = 6
    iLastRow = 81
    excludeRows = Array(7, 20, 61, 62)



    For i = iFirstRow To iLastRow
        Dim bExcludedRow As Boolean
        bExcludedRow = False
        For Each eR In excludeRows
            If eR = i Then
                bExcludedRow = True
            End If
        Next
        If bExcludedRow = False Then
            Range(sSecCol + LTrim(Str(i)) + ":" + sLastCol + LTrim(Str(i))).Select
            Selection.Copy
            Range(sFirstCol + LTrim(Str(i)) + ":" + sSLastCol + LTrim(Str(i))).Select
            ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, IconFileName:=False
            Range(sLastCol + LTrim(Str(i))).Select
            Selection.ClearContents
        End If
    Next

    Range(sFirstCol + LTrim(Str(iFirstRow + 1))).Select
    ActiveCell.FormulaR1C1 = "='Sheet1'!R[4]C[2]"
    Range(sLastCol + LTrim(Str(iFirstRow))).Select
    ActiveCell.FormulaR1C1 = "=RC[-1]+7"

    Range("A1").Select

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:21:03+00:00Added an answer on May 26, 2026 at 1:21 am

    Here are some pointers that will speed up your code:

    Dim all you variables

    Dim i As long
    Dim eR As variant
    

    At the start of your routine, set Calculation to Manual, turn off ScreenUpdating and Events.

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    

    Turn them on again at the end

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = true
    

    Don’t Select ranges you want to process. Set a variable and act on that. Example:

    Dim rng as Range
    Set rng = Range(sSecCol + LTrim(Str(i)) + ":" + sLastCol + LTrim(Str(i)))
    rng.Copy
    

    Don’t act on you sheet one row at a time, act on a contiguous range. In this case this will involve some more complex calculations to work out the rows between excluded rows, but it will have a net benefit.

    There are many ways to ‘move’ the data, some probably faster than Copy, Paste, Clear. But once you have applied the hints above you may find the routine runs fast enough. If not, post again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document that I'm parsing text out of - I'm trying to
I have a pdf document that has form fields that I'm filling out programatically
I have a document that I want to be flipped / rotated 180 degrees
I have a document that looks something like <root> <element> <subelement1 /> <subelement2 />
I have a document that is an overview document within a folder, there are
I have an XML document that I'm trying to style via CSS. A relevant
I have a Word document that starts with a Table of Contents. I need
I have an HTML document that is using to embed a control. In some
I have a PDF document that needs to be pulled up in the browser,
I have an XML document that I generate from an Entity Framework object. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.