• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

I'm teaching myself some VBA, wanna help?

dan_l

Active Member
So I've decided to join the darkside and ummm...actually learn some vba. I'm not real excited about it, but it kinda has to be done. It's not like this is my first time picking up some programming or even a little VBA, but it's been a while, so I'm basically starting from scratch.


I'm kind of a 'learn by example' kind of guy, so if you've got a couple of short snippets of vba that do something---anything, please share. Even if it's rudimentary, I could use it just for picking up little bits and pieces.


As an example:

------

Sub testingsomestuff()

Dim testing As Integer

testing = ActiveCell.FormulaR1C1


If testing < 8 Then

MsgBox ("You're screwed")

End If


If testing > 8 Then

MsgBox ("All good")

End If


End Sub

---


Only marginally more complicated than "hello world". Compares your selected sell to the 8. Why 8 you ask? I have no idea.
 
Dan_I

Diving in is the best way to learn, especially if you have a project to aim for


A few Suggestions


- Write small bits of code and test

- Dont forget about all possibilities for a variable, in your example testing could = 8

- Use Google and sites like this, no need to waste hours looking to reinvent the wheel

- If you see new idea, code or algorithms, study them and pull them apart until you understand what is going on, better to learn from others than rely on them blindly

- Ask for help, we actually do enjoy helping

- When posting code here put a ` around (before & after) the code its the button under ~, that way it maintains its indents

- Try not to use fixed values as it limits your freedom down the track

- Use Comments to remind yourself and document your code

[pre]
Code:
Sub testingsomestuff()

TestVal = 8 'What I am testing for

If [A1] < TestVal Then
MsgBox ("You're screwed") 'If its less than my test value do this
ElseIf [A1] > TestVal Then
MsgBox ("All good")  'If its greater than my test value do this
Else
MsgBox ("Dont forget it could be 8") '= my test value
End If

End Sub
[/pre]
 
Ok, for my next trick:


Problem:

SAP is a pain. Some of it's reports are unreliable in terms of output. Frequently, field names are garbled which requires extra steps prior to importing it into access, which is a prerequisite for ultimately getting it into Excel.


Solution:

http://www.codeforexcelandoutlook.com/excel-vba/write-values-to-a-header-row/


I got sum learning to do....
 
Can you post a sample of the SAP output file somewhere

make sure it has no identifying data
 
Back
Top