Chaos Project

Game Development => Sea of Code => Topic started by: diagostimo on April 28, 2012, 09:28:12 pm

Title: [resolved]help with macro in excel
Post by: diagostimo on April 28, 2012, 09:28:12 pm
hey guys, so i need a little help with a macro for excel, i have got it to do what i want it to do but i want to restrict it, heres the code for the macro:
Spoiler: ShowHide
Sub Macro1()
   Dim t
   t = Split(Worksheets("Sheet1").Range("d5").Text, "/")
   t(0) = Format(t(0) + 1, "0")
   Worksheets("Sheet1").Range("d5") = Join(t, "/")
'
End Sub
Sub Macro2()
   Dim t
   t = Split(Worksheets("Sheet1").Range("d5").Text, "/")
   t(0) = Format(t(0) - 1, "0")
   Worksheets("Sheet1").Range("d5") = Join(t, "/")
'
End Sub '

so macro1 +1 to d5 and macro 2 subtracts 1, the restriction i want to put onto it is say d5 = 0 i dont want to be able to subtract from it, i want to put a maximum restriction on it to so say d5 = 20 i dont want it to be able to add any more to it, is it possibe to do something like this with macro's???
edit:
figured out how to do it, for whoever it mat concern the code now looks like this:
Spoiler: ShowHide
Sub Macro1()
   Dim t
   t = Split(Worksheets("Sheet1").Range("d5").Text, "/")
   If Not t(0) = 5 Then
     t(0) = Format(t(0) + 1, "0")
     Worksheets("Sheet1").Range("d5") = Join(t, "/")
   End If
'
End Sub
Sub Macro2()
   Dim t
   t = Split(Worksheets("Sheet1").Range("d5").Text, "/")
   If Not t(0) = 0 Then
     t(0) = Format(t(0) - 1, "0")
     Worksheets("Sheet1").Range("d5") = Join(t, "/")
   End If
'
End Sub '
Title: Re: [resolved]help with macro in excel
Post by: ForeverZer0 on April 28, 2012, 11:54:24 pm
I would have helped, but for all the programming I know, I still know nothing about Excel. I never use it.
Title: Re: [resolved]help with macro in excel
Post by: diagostimo on April 29, 2012, 12:03:57 am
its cool :D excel uses vb, the one that i hate most of all :P