+ Reply to Thread
Results 1 to 7 of 7

Changing ranges of current code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Changing ranges of current code

    I have the following code that copies as values the range E59:E93 and then skips 25 columns and repeats the same procedure. I would like to change the code to copy as values the range E59:E93 to G59:G93 ONLY if the number "1" is in A60. The procudure should run in a loop similar to its current format. Can anyone help? Thanks
    Attached Files Attached Files
    Last edited by rhudgins; 04-14-2011 at 01:42 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Changing ranges of current code

    rhudgins,

    Would the macro loop every 25 columns from G if A60=1? Or would it loop every 25 columns from E still, it would just start at column G instead of E?

    ~tigeravatar

  3. #3
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Changing ranges of current code

    The code will copy as values the range E59:E93 to G59:G93 if A60=1. Then the code will skip 25 columns and copy as values the range AD59:AD93 to AF59:AF93 if Z60=1.... continue this sequence in a loop as more data will be added to the worksheet over time

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Changing ranges of current code

    rhudgins,

    Change this line of code:
    Set rngConvert = ActiveSheet.Range("E59:E93").Offset(0, CurrentColumn)



    To be this instead:
    Set rngConvert = ActiveSheet.Range("E59:G93").Offset(0, CurrentColumn)


    Hope that helps,
    ~tigeravatar

  5. #5
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Changing ranges of current code

    I must not have been clear in my previous post. I meant copy the range E59:E93 and paste it as values to the range G59:G93 only if A60=1...... ect.....

    Is this clearer? Sorry for the confusion.

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Changing ranges of current code

    rhudgins,

    Ah, I think I see what you mean now. Try this macro:

    Private Sub PasteValuesRediLinks()
        
        Dim rngConvert As Range
        Dim rngCheck As Range
        Dim CurrentColumn As Long:  CurrentColumn = 0
        Dim LastColumn As Long:     LastColumn = ActiveSheet.Cells(59, Columns.Count).End(xlToLeft).Column
        While CurrentColumn <= LastColumn
            Set rngConvert = ActiveSheet.Range("E59:E93").Offset(0, CurrentColumn)
            Set rngCheck = ActiveSheet.Range("A60").Offset(0, CurrentColumn)
            rngConvert.Value = rngConvert.Value
            rngConvert.Font.ColorIndex = xlAutomatic
            rngConvert.Font.TintAndShade = 0
            If rngCheck.Value = 1 Then
                rngConvert.Copy
                rngConvert.Offset(0, 2).PasteSpecial xlPasteAll, Transpose:=False
            End If
            CurrentColumn = CurrentColumn + 25
        Wend
        
    End Sub


    Hope that helps,
    ~tigeravatar

  7. #7
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Changing ranges of current code

    Thank you. This works perfectly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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