Results 1 to 5 of 5

How to reference every nth cell in a column

Threaded View

  1. #1
    Registered User
    Join Date
    02-12-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    32

    How to reference every nth cell in a column

    Helo,

    I have a data entry spreadsheet that contains 120 data entry panels each of 10 rows. Each panel is separated by 3 rows (1 of which is hidden). When entering data to the panel the user is required to enter a date in column F of the data entry panel. The number of used rows in each data entry panel can vary from 1 to 10.

    The entry of a date in the first Column F cell in each entry panel stamps today's date in Col F in the first row below each data panel (the hidden row) and that date is then linked to a separate summary sheet to show the date of data entry. The code I'm using for the date stamping routine is below, and although it works it is painfully slow and I'm sure very inefficient. I've had to break the code into the three sections as shown below because there seems to be a limit to the number of individual cells I can reference in each of the range statements. (Is there a limit or is the length of the range statement causing some other problem?)

    My vba skills are still pretty limited and I can't crack a way to make this code faster/better/more efficent. Can anyone assist with changes to the code below to reference every 13th cell rather than list each 13th cell separately as I've done? Any help will be greatly appreciated.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        ' Set date of first entry for month to TODAY() - date value is locked
    
        If Target.Cells.Count > 1 Then Exit Sub
        ' Reference first date cell for each panel
        If Not Intersect(Target, Range("F26,F39,F52,F65,F78,F91,F104,F117,F130,F143,F156,F169,F182,F195,F208,F221,F234,F247,F260,F273,F286,F299,F312,F325,F338,F351,F364,F377,F390,F403,F416,F429,F442,F455,F468,F481,F494,F507,F520,F533,F546,F559,F572,F585,F598,F611,F624,F637")) Is Nothing Then
        ' Offset TODAY() entry to cell 11 cells below target cell
            With Target(11, 1)
                .Value = Date
            End With
        End If
    
        If Target.Cells.Count > 1 Then Exit Sub
        ' Reference first date cell for each panel
        If Not Intersect(Target, Range("F650,F663,F676,F689,F702,F715,F728,F741,F754,F767,F780,F793,F806,F819,F832,F845,F858,F871,F884,F897,F910,F923,F936,F949,F962,F975,F988,F1001,F1014,F1027,F1040,F1053,F1066,F1079,F1092,F1105")) Is Nothing Then
        ' Offset TODAY() entry to cell 11 cells below target cell
            With Target(11, 1)
                .Value = Date
            End With
        End If
    
        If Target.Cells.Count > 1 Then Exit Sub
        ' Reference first date cell for each panel
        If Not Intersect(Target, Range("F1118,F1131,F1144,F1157,F1170,F1183,F1196,F1209,F1222,F1235,F1248,F1261,F1274,F1287,F1300,F1313,F1326,F1339,F1352,F1365,F1378,F1391,F1404,F1417,F1430,F1443,F1456,F1469,F1482,F1495,F1508,F1521,F1534,F1547,F1560,F1573")) Is Nothing Then
        ' Offset TODAY() entry to cell 11 cells below target cell
            With Target(11, 1)
                .Value = Date
            End With
        End If
    
    End Sub
    Last edited by glenin; 08-26-2009 at 10:10 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