+ Reply to Thread
Results 1 to 6 of 6

code to work for odd rows only

Hybrid View

kosherboy code to work for odd rows only 07-04-2014, 10:16 AM
kosherboy Re: code to work for odd rows... 07-04-2014, 10:26 AM
AB33 Re: code to work for odd rows... 07-04-2014, 10:40 AM
kosherboy Re: code to work for odd rows... 07-04-2014, 10:49 AM
mikerickson Re: code to work for odd rows... 07-04-2014, 10:53 AM
kosherboy Re: code to work for odd rows... 07-04-2014, 10:58 AM
  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    code to work for odd rows only

    Hi,
    I am trying to add to this "if" statement that it should only work for rows that are odd and i came up with this:
         If .Row = Odd And .Range("A" & rCell) <> "" And .Range("L" & rCell) = "" Then
    '
    'Rest of code
    '
    '
    but it doesn't work.
    Any ideas?

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

    Re: code to work for odd rows only

    If it's helpful here is the whole code
    Sub PO_Not_Placed()
    Application.EnableEvents = False
    Dim ws1 As Worksheet: Set ws1 = Sheets("Report Center")
    Dim RC_LR As Long
    Dim PO_LR As Long
    Dim rCell As Long
    Sheets("Report Center").Select
      With Sheets("Pending Orders")
         For rCell = 5 To .Range("A" & Rows.Count).End(xlUp).Row
                   If .Range("A" & rCell) <> "" And .Range("L" & rCell) = "" Then 'I WOULD LIKE FOR THIS ARGUMENT TO WORK ONLY FOR ODD ROWS
                           With Union(.Range("A" & rCell), .Range("C" & rCell))
                            .Copy
                               ws1.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlFormats
                               ws1.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
                               ActiveSheet.Paste
                                   Application.CutCopyMode = False
    With Sheets("Report Center").Range("A:AO")
    .FormatConditions.Delete
    End With
                           End With
                   End If
         Next rCell
      End With
    Application.EnableEvents = True
    End Sub

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: code to work for odd rows only

    Try this line

     If IsOdd(rCell) Then
    and add end if

    OR

    If rCell Mod 2 = 1 Then

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

    Re: code to work for odd rows only

    Hi AB33,
    Your 2nd suggestion worked just fine.
    Thanks!

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: code to work for odd rows only

    You could avoid testing for odd row if the loop only went through odd row numbers
    For rCell = 5 To .Range("A" & Rows.Count).End(xlUp).Row Step 2
    
        If .Range("A" & rCell) <> "" And .Range("L" & rCell) = "" Then 'I WOULD LIKE FOR THIS ARGUMENT TO WORK ONLY FOR ODD ROWS
    
    ' more code
    
    Next rCell
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

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

    Re: code to work for odd rows only

    Hi mikerickson,
    That is an impressive alternative.
    Thanks.

+ 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. [SOLVED] How to make the macro work for all rows in the work sheet
    By Valli nayaki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2013, 10:43 PM
  2. [SOLVED] Code to work on rows 9-220 only
    By Grf in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-12-2012, 05:49 AM
  3. Copy rows from work sheets to combine to one work sheet based on cell value
    By joemcmillen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2008, 05:04 PM
  4. Replies: 2
    Last Post: 07-11-2006, 11:15 PM

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