+ Reply to Thread
Results 1 to 8 of 8

Modify a Loop to take N/A Values into Account.

  1. #1
    Registered User
    Join Date
    08-27-2013
    Location
    SG
    MS-Off Ver
    2010
    Posts
    12

    Modify a Loop to take N/A Values into Account.

    Hello,

    I was hoping someone here can help me with the current issue I am running into.
    I found some code online that will look through Columns A to F, and copy and paste any values in the empty cells above it.
    However the code runs into an issue if the values are N/A. Is there anyway to modify this?

    Code:

    Dim columnValues As Range, i As Long, c As Integer
    Dim cellend As Integer
    cellend = ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row
    For c = 1 To 6 'column numbers
    For i = 3 To cellend - 1
    If Cells(i, c).Value <> "" And Cells(i + 1, c).Value = "" Then '<---- This is where the error is occurring!!!
    Cells(i + 1, c).Value = Cells(i, c).Value
    End If
    Next i
    Next c



    Any help is appreciated!

    Thanks guys!
    Last edited by vpapolu24; 10-26-2017 at 02:04 PM.

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

    Re: Modify a Loop to take N/A Values into Account.

    Please Login or Register  to view this content.
    Last edited by AB33; 10-26-2017 at 02:08 PM.

  3. #3
    Registered User
    Join Date
    08-27-2013
    Location
    SG
    MS-Off Ver
    2010
    Posts
    12

    Re: Modify a Loop to take N/A Values into Account.

    Thank you AB33 for this!


    I'm not the best with coding, so my question is: is your reply an amendment to my original code? if so where should I incorporate it.
    OR is it a completely new module.

    Thanks!

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

    Re: Modify a Loop to take N/A Values into Account.

    I have only added a single line to skip the row if it has an error-N/A

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-27-2013
    Location
    SG
    MS-Off Ver
    2010
    Posts
    12

    Re: Modify a Loop to take N/A Values into Account.

    Hi AB33,

    Thanks again,
    However I incorporated your code into my worksheet, and the macro still runs an error when it gets to a cell that is #N/A.
    When I am debugging, the code higlights the following line:


    Dim columnValues As Range, i As Long, c As Integer
    Dim cellend As Integer
    cellend = ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row

    For c = 1 To 6 'column numbers
    For i = 3 To cellend - 1
    If Not IsError(Cells(i, c).Value) Then
    If Cells(i, c).Value <> "" And Cells(i + 1, c).Value = "" Then '<----error still occurring!
    Cells(i + 1, c).Value = Cells(i, c).Value
    End If
    End If
    Next i
    Next c

  6. #6
    Registered User
    Join Date
    08-27-2013
    Location
    SG
    MS-Off Ver
    2010
    Posts
    12

    Re: Modify a Loop to take N/A Values into Account.

    My question in this case would be is there a way to copy the #N/A and paste it to the next cell in the bottom.

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

    Re: Modify a Loop to take N/A Values into Account.

    Okay, I did not see, you are comparing to next row.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-27-2013
    Location
    SG
    MS-Off Ver
    2010
    Posts
    12

    Re: Modify a Loop to take N/A Values into Account.

    That did the trick!

    Thanks so much!!!!!

+ 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. Replies: 4
    Last Post: 03-31-2016, 05:50 AM
  2. How to Loop through Column and Modify Values Based on User Input
    By bryanmarks in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2015, 11:38 AM
  3. [SOLVED] Modify Loop Code
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-29-2014, 10:43 AM
  4. Trying to Modify Mail VBA to loop and add attachment
    By vdep in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2013, 02:03 PM
  5. [SOLVED] For Each loop doesn't take every row into account
    By Tino XXL in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-15-2012, 07:54 AM
  6. Modify This Code for WorkBook Loop
    By Pukka83 in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 06-24-2008, 05:39 AM
  7. [SOLVED] Loop through, open, and modify all workbooks in file
    By Jason in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2005, 05:05 PM

Tags for this Thread

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