Last active
January 4, 2019 00:16
Star
You must be signed in to star a gist
Basic vba statements - frequent uses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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