+ Reply to Thread
Results 1 to 11 of 11

Is there a mistake in the code

  1. #1
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Post Is there a mistake in the code

    I need to learn from my below code which is as below:

    Please Login or Register  to view this content.

    The If cell line ……………contains cell.Offset(0, 3) Then cell.Offset(0, 3) = cell

    Else cell.Offset(0, 3) = cell

    What is confusing me that the Logical_test is same but Value_if_true & Value_if_false is also same! Is there some error in writing the code? If error is not there, what does above lines in the code would result into?

    Explanation would be appreciated.
    Last edited by bittubadri; 10-20-2019 at 03:15 PM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Is there a mistake in the code

    The way you have written the code, cell.offset(0,3) will always equal cell. Explain in words what you are trying to do. What value do you want for cell.offset(0,3) if cell is greater than cell.offset(0,3) and what value do you want if cell is not greater than cell.offset(0,3)?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Is there a mistake in the code

    Quote Originally Posted by Mumps1 View Post
    The way you have written the code, cell.offset(0,3) will always equal cell. Explain in words what you are trying to do. What value do you want for cell.offset(0,3) if cell is greater than cell.offset(0,3) and what value do you want if cell is not greater than cell.offset(0,3)?
    I want to obtain Highest value from D8:D10000

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Is there a mistake in the code

    If you simply want the highest value then try: =MAX(D8:D10000)

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,860

    Re: Is there a mistake in the code

    @bittubadri

    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.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Is there a mistake in the code

    Included code tags around code. Learnt to add code tags, thanks for this. Would certainly do this code tagging in future.
    Last edited by alansidman; 10-20-2019 at 04:06 PM.

  7. #7
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Is there a mistake in the code

    Quote Originally Posted by Mumps1 View Post
    If you simply want the highest value then try: =MAX(D8:D10000)
    D8:D10000 is linked to another Worksheet ("Sheet7") cells L8:L10000 (on the same Workbook). L8:L10000 ("Sheet7") regularly keeps on updating through dynamic data feeds from a software which generates values & is linked to L8:L10000 ("Sheet7") when both software & the Excel Workbook is kept open. The speed of generation of values in L8:L10000 ("Sheet7") is very fast. But still the vba can perform its desired action of obtaining Highest value from D8:D10000

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Is there a mistake in the code

    OK, but is the formula I suggested doing what you want?

  9. #9
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Is there a mistake in the code

    Administrative Note:

    Please don't quote entire posts unnecessarily. They are just clutter and make threads hard to read.
    Use the "Quick reply" instead
    Thanks

  10. #10
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Is there a mistake in the code

    No it does not

  11. #11
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Is there a mistake in the code

    It would be easier to help if you could attach a copy of your file. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using examples from your data.

+ 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] Part of VBA code won't execute as I planned it to do - Probably a simple mistake !!
    By hans302 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2018, 01:09 PM
  2. [SOLVED] New to VBA - Where's my mistake with this small bit of code?
    By OpieWinston in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2017, 10:25 AM
  3. [SOLVED] Mistake in code
    By jj4jj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2016, 11:11 AM
  4. Where Is My Code Mistake For Listbox ?
    By blackvba in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2008, 02:29 AM
  5. VB code almost works...but can't find a minor mistake
    By NadiaR via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-16-2006, 01:35 PM
  6. Code mistake
    By Mirko Barkovic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-29-2005, 10:00 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