Results 1 to 16 of 16

Changing ranges of code

Threaded View

rhudgins Changing ranges of code 03-15-2011, 12:59 PM
pike Re: Changing ranges of code 03-16-2011, 05:43 AM
pike Re: Changing ranges of code 03-16-2011, 07:03 AM
rhudgins Re: Changing ranges of code 03-16-2011, 11:37 AM
pike Re: Changing ranges of code 03-16-2011, 09:23 PM
rhudgins Re: Changing ranges of code 03-17-2011, 10:06 AM
pike Re: Changing ranges of code 03-18-2011, 12:55 AM
snb Re: Changing ranges of code 03-18-2011, 04:16 AM
rhudgins Re: Changing ranges of code 03-18-2011, 11:11 AM
pike Re: Changing ranges of code 03-18-2011, 04:16 PM
snb Re: Changing ranges of code 03-18-2011, 04:42 PM
rhudgins Re: Changing ranges of code 03-18-2011, 04:53 PM
pike Re: Changing ranges of code 03-18-2011, 05:21 PM
pike Re: Changing ranges of code 03-18-2011, 05:28 PM
snb Re: Changing ranges of code 03-18-2011, 05:35 PM
teylyn Re: Changing ranges of code 03-19-2011, 05:21 AM
  1. #1
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Changing ranges of code

    I would like to change the entire code so each range will include data from column O. I tried to change the ranges below but I am not sure how to edit the entire code. Can anyone help? Thanks


        Const sSOURCE_NAME  As String = "Mkt Open"
        Const sTARGET_NAME  As String = "Tkr Consolidation"
        Const sTOP_CELL     As String = "A2"
        Const sRANGE_1      As String = "J10:J19,O10:O19"
        Const sRANGE_2      As String = "J23:J42,O23:O42"
        Const sRANGE_3      As String = "J50:J59,O50:O59"
        Const sRANGE_4      As String = "J63:J82,O63:O82"
        Const sRANGE_5      As String = "J90: J99,O90:O99"
        Const sRANGE_6      As String = "J103:J122,O103:O122"
        Const sRANGE_7      As String = "J130:J139,O130:O139"
        Const sRANGE_8      As String = "J143:J162,O143:O162"
        Const sRANGE_9     As String = "J170:J179,O170:O179"
        Const sRANGE_10     As String = "J183:J202,O183:O202"
        Const sRANGE_11     As String = "J210:J219,O210:O219"
        Const sRANGE_12     As String = "J223:J242,O223:O242"
        Const sRANGE_13     As String = "J250:J259,O250:O259"
        Const sRANGE_14     As String = "J263:J282,O263:O282"
        Const sRANGE_15     As String = "J290:J299,O290:O299"
        Const sRANGE_16     As String = "J303:J322,O303:O322"
        Const sRANGE_17     As String = "J330:J339,O330:O339"
        Const sRANGE_18     As String = "J343:J362,O343:O362"
        Const sRANGE_19     As String = "J370:J379,O370:O379"
        Const sRANGE_20     As String = "J383:J402,O383:O402"

    Entire Code
    Sub TickerConsolidationShares()
        Application.ScreenUpdating = False
        
        Const sSOURCE_NAME  As String = "Mkt Open"
        Const sTARGET_NAME  As String = "Tkr Consolidation"
        Const sTOP_CELL     As String = "A2"
        Const sRANGE_1      As String = "V10:V19"
        Const sRANGE_2      As String = "V23:V42"
        Const sRANGE_3      As String = "V50:V59"
        Const sRANGE_4      As String = "V63:V82"
        Const sRANGE_5      As String = "V90:V99"
        Const sRANGE_6      As String = "V103:V122"
        Const sRANGE_7      As String = "V130:V139"
        Const sRANGE_8      As String = "V143:V162"
        Const sRANGE_9      As String = "V170:V179"
        Const sRANGE_10     As String = "V183:V202"
        Const sRANGE_11     As String = "V210:V219"
        Const sRANGE_12     As String = "V223:V242"
        Const sRANGE_13     As String = "V250:V259"
        Const sRANGE_14     As String = "V263:V282"
        Const sRANGE_15     As String = "V290:V299"
        Const sRANGE_16     As String = "V303:V322"
        Const sRANGE_17     As String = "V330:V339"
        Const sRANGE_18     As String = "V343:V362"
        Const sRANGE_19     As String = "V370:V379"
        Const sRANGE_20     As String = "V383:V402"
                                    
    
    
        Dim vaDataValues    As Variant
        Dim rTargetCells    As Range
        Dim rSourceCells    As Range
        Dim rStartCell      As Range
        Dim sDataValue      As String
        Dim wksSource       As Worksheet
        Dim wksTarget       As Worksheet
        Dim iDataCell       As Integer
        Dim rTopCell        As Range
        Dim vRange          As Variant
    
        Set wksSource = ThisWorkbook.Sheets(sSOURCE_NAME)
        Set wksTarget = ThisWorkbook.Sheets(sTARGET_NAME)
    
        Set rTopCell = wksTarget.Range(sTOP_CELL)
        Set rStartCell = rTopCell
    
    '   Copy the three ranges of source data to the target worksheet
        For Each vRange In Array(sRANGE_1, sRANGE_2, sRANGE_3, sRANGE_4, sRANGE_5, sRANGE_6, sRANGE_7, sRANGE_8, sRANGE_9, sRANGE_10, sRANGE_11, sRANGE_12, sRANGE_13, sRANGE_14, sRANGE_15, sRANGE_16, sRANGE_17, sRANGE_18, sRANGE_19, sRANGE_20)
    
            Set rSourceCells = wksSource.Range(vRange)
            vaDataValues = rSourceCells.Value
    
            Set rTargetCells = Range(rStartCell, _
                                    rStartCell.Offset(rSourceCells.Rows.Count - 1, 0))
            rTargetCells.Cells.Clear
            rTargetCells.Value = vaDataValues
    
            Set rStartCell = rStartCell.Offset(rSourceCells.Rows.Count, 0)
    
        Next vRange
    
        Set rTargetCells = Range(rTopCell, rStartCell.Offset(-1, 0))
        With rTargetCells
    
    '       Sort the newly-copied source data (including blank rows) on the target worksheet
            .Sort Key1:=.Cells(1, 1), Order1:=xlAscending, Header:=xlNo
    
    '       Remove duplicate values from the sorted list of source data
            sDataValue = .Cells(1, 1).Value
            For iDataCell = 2 To rTargetCells.Cells.Count
                If sDataValue = rTargetCells.Cells(iDataCell, 1).Value Then
                      rTargetCells.Cells(iDataCell, 1).ClearContents
                Else: sDataValue = rTargetCells.Cells(iDataCell, 1).Value
                End If
            Next iDataCell
    
    '       Finally, sort the data list again to remove blank (formerly duplicate) values
            .Sort Key1:=.Cells(1, 1), Order1:=xlAscending, Header:=xlNo
    
        End With
        
            Application.ScreenUpdating = True
    
    End Sub
    Last edited by rhudgins; 03-18-2011 at 05:15 PM.

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