Skip to content

Instantly share code, notes, and snippets.

@zbyna zbyna/frequent.vba

Last active Jan 4, 2019
Embed
What would you like to do?
Basic vba statements - frequent uses
Sub TotoTlacitka_Click()
' callback for button with name TotoTlacitka, _ is part of vba syntax
' early binding
Dim Aktualni_vyber As Range
Dim bunka As Range
Dim cislo As Integer
' object initialisation
Set Aktualni_vyber = Selection
For Each bunka In Aktualni_vyber
Set bunka = Porovnej(bunka)
Next bunka
'free object
Set Aktualni_vyber = Nothing
End Sub
Function Porovnej(ByRef bunka As Range) As Range
' not for direct using from Excel cell b/c returns object and thus create circular reference
If bunka.Value <= 10 Then
bunka.Offset(0, 1).Value = "< = 10 "
ElseIf bunka.Value > 10 And bunka.Value <= 20 Then
bunka.Offset(0, 1).Value = "< = 20"
ElseIf bunka.Value > 20 And bunka.Value <= 30 Then
bunka.Offset(0, 1).Value = "< = 30"
Else
bunka.Offset(0, 1).Value = "> 30"
End If
Set Porovnej = bunka
End Function
Function PorovnejPrimoZBunky(ByRef bunka As Range) As String
' for direct using from Cell in Excel, returns text
If bunka.Value <= 10 Then
PorovnejPrimoZBunky = "< = 10 "
ElseIf bunka.Value > 10 And bunka.Value <= 20 Then
PorovnejPrimoZBunky = "< = 20"
ElseIf bunka.Value > 20 And bunka.Value <= 30 Then
PorovnejPrimoZBunky = "< = 30"
Else
PorovnejPrimoZBunky = "> 30"
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.