+ Reply to Thread
Results 1 to 14 of 14

"if currentcell's row < row 1600 then"..

  1. #1
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Talking "if currentcell's row < row 1600 then"..

    i have the following psudo code, could someone please show me how to put it to code in vba? ive never used vba so im not very fluent yet.

    For Each cell In DataRange

    if cell row = row 1600 then

    cell row = 1700 (and continue going through DataRange)

    end if

    next

    thanks!
    - Adam

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: "if currentcell's row < row 1600 then"..

    Hi Adam,

    Can you explain what you are trying to achieve with this? I don't know whether "cell row' is a variable or a reference to the row number of a cell. And even then it doesn't make a lot of sense - at least to me since there is only one row 1600.

    In addition upload an example workbook showing what the before and after result should be.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: "if currentcell's row < row 1600 then"..

    Quote Originally Posted by Richard Buttrey View Post
    Hi Adam,

    Can you explain what you are trying to achieve with this? I don't know whether "cell row' is a variable or a reference to the row number of a cell. And even then it doesn't make a lot of sense - at least to me since there is only one row 1600.

    In addition upload an example workbook showing what the before and after result should be.

    Regards
    "cell row"is psudo code to represent the row of the variable "cell" because i dont know what the actual code is

  4. #4
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: "if currentcell's row < row 1600 then"..

    what im trying to do is actually really complicated, but im trying to maneuver through some data. My code looks through the dates on a data range and makes a bunch of calculations for each week and month but it requires the data to be in order by date. recently a bunch of old data was added and the dates cross over where the new data starts, so im trying to code a little work-around

  5. #5
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: "if currentcell's row < row 1600 then"..

    my data range is going through a single column, so basically the code above is going through the cells in the column, and once it gets to row 1600 it jumps to row 1700.

    thats all i want to know how to do

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: "if currentcell's row < row 1600 then"..

    Hi,

    It would assist greatly if you could upload the workbook. I'm still not clear why the reference to row constants 1600 & 1700. Can't you sort the data by date first? I'm not clear what you mean by dates 'crossing over'.

    Regards

  7. #7
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: "if currentcell's row < row 1600 then"..

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    It would assist greatly if you could upload the workbook. I'm still not clear why the reference to row constants 1600 & 1700. Can't you sort the data by date first? I'm not clear what you mean by dates 'crossing over'.

    Regards
    well i made my file under 1000 kb but for some reason i cant seem to upload it.

    but i cant sort the data first because some of it is from an old file which was copied in and the rest is constantly changing data that is imported by from a query. what i mean by them "crossing over" is that the first set of data goes from Jan 2010 - Dec 2010 and the query data goes from June 2010 - present.

    but what im trying to do is irrelevant, all im asking is how do i put my pseudo code into real code. i should be able to figure out the rest on my own if you could help me with that..

    soo.... the portion in quotations is psudo code
    ----------------------------------------------------------------------------------------------

    Dim DataRange As Range, cell As Range

    Set DataRange = Range("'NCMR Data'!C2:C65536")

    For Each cell In DataRange

    if "cell row" = "1600" then

    "cell row = 1700"

    //(so if the present row of "cell" is 1600, change row value to 1700 and continue going through DataRange)

    end if

    next

    ----------------------------------------------------------------------------------------------

    does that make sense?

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: "if currentcell's row < row 1600 then"..

    What you are trying to do doesn't really make sense, but I think your basic requirement is just:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  9. #9
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: "if currentcell's row < row 1600 then"..

    i know it doesnt make sense, its because i've taken it out of context.

    but no that wont work, i need to do it with an if statement. is there any way?

    thanks for the help tho
    Last edited by romperstomper; 03-28-2011 at 11:02 AM. Reason: remove unnecessary quote

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: "if currentcell's row < row 1600 then"..

    Why do you need an If statement? You can't skip through a For Each loop like that - you can use two loops (2 to 1600, then 1700 onward), or you could test the row number every time and simply ignore it if it's between 1600 and 1700 but that's pointless.

  11. #11
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: "if currentcell's row < row 1600 then"..

    i need an if statement because it wont always be the same rows, i just used 1600 and 1700 as an example.

  12. #12
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: "if currentcell's row < row 1600 then"..

    Quote Originally Posted by romperstomper View Post
    Why do you need an If statement? You can't skip through a For Each loop like that - you can use two loops (2 to 1600, then 1700 onward), or you could test the row number every time and simply ignore it if it's between 1600 and 1700 but that's pointless.
    how do i test the row every time and ignore it? that would help

  13. #13
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: "if currentcell's row < row 1600 then"..

    You could use Select Case:
    Please Login or Register  to view this content.
    or use two loops which is more efficient if it's one gap in the middle:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    03-22-2011
    Location
    ontario, canada
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: "if currentcell's row < row 1600 then"..

    Quote Originally Posted by romperstomper View Post
    You could use Select Case:
    Please Login or Register  to view this content.
    or use two loops which is more efficient if it's one gap in the middle:
    Please Login or Register  to view this content.
    okay thanks a lot, i think i see how i can do this now

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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