Results 1 to 24 of 24

Thread: help with coding

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:42 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: help with coding

    Given that this is almost certainly homework and it would be cheating for us to write your code for you, how about you make your best attempt at doing it for yourself and then, if you encounter issues, you provide us with your code and an explanation of exactly where you're stuck, e.g. how the behaviour of your code differs from the desired behaviour, and then we can help you fix those issues specifically. Despite what some people would have you believe, the best way to learn is by doing, sure, examples and the like are important but there are a ton of examples out there already so if our providing more doesn't really help you learn anything more. If you try to solve the problem for yourself and then we show what was wrong with your reasoning, it helps you avoid similar faulty reasoning in the future.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: help with coding

    Aside from that, the description sounds like something done in Excel, not in .NET. If that's the case, I'll move the thread to the Office Development forum.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:43 PM.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: help with coding

    If it is Excel, do you need to use VB.NET for some reason? What you described sounds like it would be better suited as a macro, which would be VBA. If a macro will suffice, then what I would suggest is that you turn on the macro recorder, then do the exact steps as you described (or as close as you can come to them), and see what the recorder output is. In general, the macro recorder will cover all that you have done, but that is almost always more than you really need to do. For example, if you click in B1 by accident, then move to A1, the recorder will faithfully record the move to B1 followed by the move to A1, even though all you really needed was the move to A1. Therefore, the recorder will have a fair amount of extra junk in it that you can throw out, but contained amidst the junk is the actual work you did. You'd have a template that showed the code, perhaps not ideal, and certainly padded with extraneous stuff, but it's an excellent way to start. All you'd have to do is examine the resulting code and use the web to look up any instructions that are not immediately obvious.

    That's pretty much how I started into spreadsheet stuff, though it wasn't in VB at the time. That first macro will have lots of garbage, and the whole thing may prove to be junk, once you get some experience, but as a means to get started, it could hardly be better.
    My usual boring signature: Nothing

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: help with coding

    Quote Originally Posted by nathon View Post
    It is not homework. It is for Excel for a project at work.
    Oh sorry, I didn't realise that, rather than homework, it was actual work that you are getting paid for that you want us to do for you. My mistake.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: help with coding

    Quote Originally Posted by jmcilhinney View Post
    Oh sorry, I didn't realise that, rather than homework, it was actual work that you are getting paid for that you want us to do for you. My mistake.
    I'd kind of agree....except that it works, sometimes. In this case, the macro recorder is likely to do a pretty fair job of it, and is worth learning for that reason, but I'd have to say that I've written some things for people here that have been put to use, and gotten a few things from people that I have put to use. One can only ask.

    However, this did prompt me to re-read the original post. This is DEFINITELY not a .NET question, as the solution pretty much HAS to be VBA to be at all useful, so I've moved the thread.
    My usual boring signature: Nothing

  8. #8
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: help with coding

    When you guys are done with that code if you could just finish those TPS report... emkaay...

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:43 PM.

  10. #10
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: help with coding

    Forgive me for asking you for help
    You didnt ask for help, you asked us to be your auto compiler

  11. #11

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:43 PM.

  12. #12

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:43 PM.

  13. #13
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: help with coding

    You still havent posted any coding that you made that doesnt work.

    no guarentees the following will work
    Code:
    
    dim wrk as workbook
    dim shtData as worksheet
    dim shtForm as worksheet
    dim rng as range
    dim lngMaxRows as long
    dim lngCurRow as long
    
    set wrk = activeworkbook
    set shtdata = wrk.sheets('Data')
    set shtform = wrk.sheets('form')
    lngMaxRows = 350 'shtData.cells(65535,2).end(xlup).row 'bottom row of data?
    
    for lngCurRow = 3 to lngMaxRows
      if shtdata.cells(lngcurrow,2) <> "" then
        if shtdata.cells(lngcurrow,3) = "" then
          shtform.cells(12,15) = shtdata.cells(lngcurrow,1)
          '--- print sheet/tab here
          shtform.print 'not sure this works
        end if
      end if
    next
    
    set rng =nothing
    set shtform=nothing
    set shtdata=nothing
    set wrk = nothing

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: help with coding

    if you want some help, post a workbook with some sample data (zip first), including whatever code you have written /recorded, with info on what does not work or works incorrectly

    it is the aim of most here to help people to write their own code, that being said, there are many instances where code is supplied (as above) that is almost complete, or will do the job, most times does not include enough error handling for real world use, where many things could go wrong
    having a sample workbook gives us something factual to test on, rather than guessing what is wanted
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  15. #15

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:44 PM.

  16. #16

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:44 PM.

  17. #17
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: help with coding

    Did it work ? I wrote it in note pad so not sure it would run...

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  18. #18

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:44 PM.

  19. #19
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: help with coding

    the code posted needs to be inside a procedure (Sub)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  20. #20

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:45 PM.

  21. #21
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: help with coding

    procedures can be functions or subs (also referred to in VBA as macros)
    functions return a result to the caller

    a sub can look like
    Code:
    Sub bbb()
    Dim d As Double
        d = 1979071148.6
        
        d = CDbl(CLng(d - 0.5))
        MsgBox d
    End Sub
    could also be several pages long, you can pass 1 or more arguments to the procedure, within the parentheses

    excel has many event driven subs, like
    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        'put your own code in here
    End Sub
    every worksheet and workbook has events that can be found in the dropdown lists of their code pages, the application also has events

    for more on this you should get a primer or google VBA procdure

    some variables can be dimensioned in the general section of the code page above all procedures, those variables are available to use (read or write) by any procedure, variables dimensioned in a procedure are only valid within that procedure
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  22. #22

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Hi Everyone,

    Thanks for your help. I was able to find another way to make it work.
    Last edited by nathon; Sep 25th, 2017 at 12:45 PM.

  23. #23
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: help with coding

    are you saying
    yes!
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  24. #24

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    11

    Re: help with coding

    Quote Originally Posted by westconn1 View Post
    yes!
    Thank you.

    That didn't make it work, but I was able to find another way to make it work. Thank you all for your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width