+ Reply to Thread
Results 1 to 10 of 10

Several IF statements that should be And statements

  1. #1
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Several IF statements that should be And statements

    I am trying to write a code to copy information from one worksheet to another that has IF Statements because of criteria that needs to be met in certain cells. But for some reason, it's not picking up the 2nd IF statement. It's giving me every type. Here is the code.

    Please Login or Register  to view this content.
    I've read about CASE statements, but I'm confused on that part. What is so weird, is that this was working, but then I changed the cell locations so now it's not picking it up correctly. Any help would be appreciated.
    Thank you.
    Last edited by vanfel; 11-23-2021 at 11:47 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Several IF statements that should be And statements

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Several IF statements that should be And statements

    Don't use GoTo. Ever.

    I can't figure out what you want your code to do, because your code will always execute this line
    Please Login or Register  to view this content.
    regardless of the If condition. If the condition is True, it goes to this statement. If it's False, it ends up there anyway.

    Also you do not have to Activate and Select objects to operate on them.

    My best guess is this. If it does not work please attach your file for testing.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: Several IF statements that should be And statements

    This code gives me a type mismatch on the If statement. Would that be because the format in those cells in the IF statements are not all text? For instance the value in Cell 53 is a number.
    I have attached a sample file.
    Attached Files Attached Files
    Last edited by vanfel; 11-23-2021 at 12:21 PM.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Several IF statements that should be And statements

    Cell BA36 has a #VALUE error. That is because the formula is using DAYS, and that function is referencing cells that have "N/A" (text). DAYS gives an error if it is expecting dates but gets text. Then when the code refers to that cell it raises an error.

    My suggestion would be to fix your formula so that it does not produce an error. Maybe something like

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: Several IF statements that should be And statements

    I fixed the cells by adding the IFERROR formula, but I get an error on the code you gave me:
    Worksheets("Buyer to Issued").Cells(b + 1, 1).EntireRow.Paste
    The error is Object doesn't support this property or method. I have tried looking this error up to understand it, but I just don't. Any suggestions on what that may be?

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

    Re: Several IF statements that should be And statements

    should be
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: Several IF statements that should be And statements

    Is there a way to only paste certain cells instead of the entire row? For instance, I only want to copy over Columns C, D, E, F, P, Q, R, T, U, V, W and AD.

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

    Re: Several IF statements that should be And statements

    Please Login or Register  to view this content.
    Last edited by AB33; 12-09-2021 at 11:22 AM.

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Several IF statements that should be And statements

    vanfel can you clarify the data layout you want on the pasted sheet?

    Quote Originally Posted by AB33 View Post
    Please Login or Register  to view this content.
    This will certainly paste the desired cells, but they will be pasted contiguously, not according to the source layout. That is, data from C:F will be pasted into A:D, data from P:R will be pasted into E:G, and data from T:W will be pasted into H:K, AD will be pasted to L. Your sample file does not have column headers on the Buyer to Issued sheet so it's hard to tell what you are expecting.

+ 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] If statements and Select statements in active controls userform
    By LaSouth1776 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-05-2020, 03:17 AM
  2. Reading If statements and formulating values from if statements
    By crnam in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-16-2013, 05:20 AM
  3. questions with if statements and nested if statements
    By Pat Excel in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 02-03-2013, 01:41 PM
  4. Multiple nested IF statements and AND statements
    By TonyGetz in forum Excel General
    Replies: 2
    Last Post: 12-14-2010, 03:07 AM
  5. Nested If statements / logic statements
    By Brainless_09 in forum Excel General
    Replies: 3
    Last Post: 06-17-2009, 02:59 PM
  6. Replies: 12
    Last Post: 05-15-2009, 08:38 AM
  7. [SOLVED] operator statements, shorting when reusing one of the statements?
    By KR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2005, 02:05 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