-
Sep 19th, 2017, 06:41 PM
#1
Thread Starter
New Member
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.
-
Sep 19th, 2017, 06:49 PM
#2
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.
-
Sep 19th, 2017, 06:52 PM
#3
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
-
Sep 20th, 2017, 07:47 AM
#4
Thread Starter
New Member
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.
-
Sep 20th, 2017, 09:37 AM
#5
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
-
Sep 20th, 2017, 09:42 AM
#6
Re: help with coding
Originally Posted by nathon
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.
-
Sep 20th, 2017, 09:54 AM
#7
Re: help with coding
Originally Posted by jmcilhinney
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
-
Sep 20th, 2017, 10:58 AM
#8
Re: help with coding
When you guys are done with that code if you could just finish those TPS report... emkaay...
-
Sep 20th, 2017, 12:05 PM
#9
Thread Starter
New Member
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.
-
Sep 20th, 2017, 12:07 PM
#10
Re: help with coding
Forgive me for asking you for help
You didnt ask for help, you asked us to be your auto compiler
-
Sep 20th, 2017, 12:09 PM
#11
Thread Starter
New Member
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.
-
Sep 20th, 2017, 12:11 PM
#12
Thread Starter
New Member
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.
-
Sep 20th, 2017, 03:51 PM
#13
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
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...
-
Sep 20th, 2017, 04:16 PM
#14
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
-
Sep 20th, 2017, 05:44 PM
#15
Thread Starter
New Member
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.
-
Sep 20th, 2017, 05:46 PM
#16
Thread Starter
New Member
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.
-
Sep 21st, 2017, 05:38 AM
#17
Re: help with coding
Did it work ? I wrote it in note pad so not sure it would run...
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...
-
Sep 21st, 2017, 06:47 PM
#18
Thread Starter
New Member
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.
-
Sep 22nd, 2017, 05:43 AM
#19
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
-
Sep 22nd, 2017, 12:16 PM
#20
Thread Starter
New Member
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.
-
Sep 22nd, 2017, 10:36 PM
#21
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
-
Sep 23rd, 2017, 02:01 PM
#22
Thread Starter
New Member
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.
-
Sep 23rd, 2017, 06:34 PM
#23
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
-
Sep 25th, 2017, 12:41 PM
#24
Thread Starter
New Member
Re: help with coding
Originally Posted by westconn1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|