+ Reply to Thread
Results 1 to 7 of 7

Working with Odd and Even rows in coding

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Working with Odd and Even rows in coding

    Hello everybody,
    The code below checks if the left cell, which is 11 cells to the left of the target cell, is duplicated anywhere in column L and then copies the value in the target cell to every cell on column W that the value of the cell that is 11 cells to the left is matching the value of the target's 11 cells to the left.
    The code is currently copying the valueinto every ODD row, i would like the code to copy the value into every EVEN row. How can i go about doing this?
    If (Target.Row > 4) And (Target.Count = 1) And (Target.Column = 23) And (Target.Row Mod 2 = 0) Then
    If Not Target.Offset(-1, -11) = "N/A" Then
         Application.EnableEvents = False
         Application.ScreenUpdating = False
         Application.Calculation = xlManual
    
         Dim mtx4(), CurrCell4, LeftCell4, i4 As Long
         'Matrix of columns L:W
         mtx4 = Intersect(ActiveSheet.UsedRange, ActiveSheet.Range("L:W")).Value
         'Value of current cell
         CurrCell4 = Target.Value
         'Value of the cell left of current cell
         LeftCell4 = Target.Offset(-1, -11).Value
         'Comparing and set if matched
         For i4 = 1 To UBound(mtx4, 1)
             If mtx4(i4, 1) = LeftCell4 Then mtx4(i4, 12) = CurrCell4
         Next i4
         
         'Write matrix back to range L:W
         Range("L1").Resize(UBound(mtx4, 1), UBound(mtx4, 2)).Value = mtx4
    
         Application.EnableEvents = True
         Application.ScreenUpdating = True
         Application.Calculation = xlCalculationAutomatic
    End If
    End If
    It would be absolutely amazing if this issue can get resolved!
    Last edited by kosherboy; 01-20-2015 at 03:31 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Working with Odd and Even rows in coding

    Hi Kosherboy,

    I notice that:
    Target.Offset(-1, -11).Value
    is the previous row as well as 11 to the left?? Hope that helps
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: Working with Odd and Even rows in coding

    Hi xladept,
    I need the code to read the value of the cell that the row is on top of the target row and 11 cells to the left 9of the target cell). Therefore the value in Leftcell4 should equal the value of the target cell minus 1 row 9up) and minus 11 columns (to the left).

    I need that the missing part of the code to do the following: The code needs to use the leftcell4 value and offset 11 cells to the right and 1 cell down of leftcell4 and then insert the value of Currcell4.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Working with Odd and Even rows in coding

    I need to see all the code

  5. #5
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: Working with Odd and Even rows in coding

    Here is an example workbook with the code EXAMPLE.xlsm
    The yellow boxes need to be all filled out automatically when any of the yellow boxes have value entered in it. My code is writing the value in the green boxes as opposed to the yellow.
    So my goal is that if i enter a "Y" in the first yellow box i want the other yellow boxes to be filled out automatically. This code is working based off the matching "PO" numbers on column L.

    Regards,
    Kosherboy

  6. #6
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: Working with Odd and Even rows in coding

    I GOT IT!
    See below blue font that i added to the code
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If (Target.Row > 4) And (Target.Count = 1) And (Target.Column = 23) And (Target.Row Mod 2 = 0) Then
            If Not Target.Offset(-1, -11) = "N/A" Then
            
                Application.EnableEvents = False
                Application.ScreenUpdating = False
                Application.Calculation = xlManual
            
                    Dim mtx4(), CurrCell4, LeftCell4, i4 As Long
                    'Matrix of columns L:W
                    mtx4 = Intersect(ActiveSheet.UsedRange, ActiveSheet.Range("L:W")).Value
                    'Value of current cell
                    CurrCell4 = Target.Value
                    'Value of the cell left of current cell
                    LeftCell4 = Target.Offset(-1, -11).Value
                    'Comparing and set if matched
                    For i4 = 1 To UBound(mtx4, 1)
                        If mtx4(i4, 1) = LeftCell4 Then mtx4(i4 + 1, 12) = CurrCell4
                    Next i4
                    
                    'Write matrix back to range L:W
                    Range("L1").Resize(UBound(mtx4, 1), UBound(mtx4, 2)).Value = mtx4
            
                Application.EnableEvents = True
                Application.ScreenUpdating = True
                Application.Calculation = xlCalculationAutomatic
                
            End If
        End If
    
    End Sub
    Solved my own thread

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Working with Odd and Even rows in coding

    Hey KosherBoy,

    Well done - I was looking at that index

    Thanks for the rep!
    Last edited by xladept; 01-21-2015 at 04:27 PM.

+ 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. Transfer coding not working
    By superdonk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2014, 10:16 AM
  2. coding previously working in Excel 2003 version not working in Excel 2010
    By petercalbra in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-11-2012, 10:51 AM
  3. [SOLVED] VBA coding only working in the first sheet. It is not working in all the sheets
    By srinivasan1965 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-16-2012, 02:04 PM
  4. Coding in VBA not working
    By paubears08 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-21-2012, 07:21 PM
  5. Deactivate coding not working??
    By tazmanian24 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2009, 07:28 AM

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