• 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.

Need help with a few pieces of code

Belleke

Well-Known Member
First question
I have this
Code:
Private Sub ComboBox1_Click()
Range(ComboBox1.LinkedCell).Offset(0, -2).Select
End Sub
This works, but instead of using this code 24 times (for 24 comboboxes), i am looking for some code Like
Code:
For each combobox in worksheet ...
Second question
I have this code (works) but it should only work for the cell that changes
Now i get 3 or more MsgBoxes when the cell value meets the criteria
Code:
Private Sub Worksheet_Calculate()
Dim rng As Range, cell As Range
Set rng = Range("J12:J22")
For Each cell In rng
If cell.Value > cell.Offset(0, -1).Value Then MsgBox "Snelheid te hoog!", vbOKOnly
End If
Next cell
End Sub
 
I didn't get the first question
As for the second try this code
Code:
Private Sub Worksheet_Calculate()
    Dim rng As Range, cell As Range
    Dim flg As Boolean
   
    flg = False
    Set rng = Range("J12:J22")
   
    For Each cell In rng
        If cell.Value > cell.Offset(0, -1).Value Then flg = True: MsgBox "Snelheid te hoog!", vbOKOnly: Exit For
    Next cell
End Sub
 
Hello Yaser,
Thank you for your time and efford.
However once 1 of the values in the range meets the criteria i get a MSGbox, it should only trigger the macro for the row i am working in.
For my first question instead of using 24 times the code, i was thingking in this direction
Code:
For Each Ctrl In ActiveWorksheet.Controls
    If TypeName(Ctrl) = "ComboBox" Then
  Range(Ctrl.LinkedCell).Offset(0, -2).Select
    End If
Next Ctrl
Can you help me a bit further
Thanks
 
Back
Top