[resolved]help with macro in excel

Started by diagostimo, April 28, 2012, 09:28:12 pm

Previous topic - Next topic

diagostimo

April 28, 2012, 09:28:12 pm Last Edit: April 28, 2012, 11:37:35 pm by diagostimo
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 '

ForeverZer0

I would have helped, but for all the programming I know, I still know nothing about Excel. I never use it.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

diagostimo

its cool :D excel uses vb, the one that i hate most of all :P