PDA

View Full Version : Solved: Help needed



Rayman
09-16-2011, 07:17 PM
I'm here again to seek help from the kind people on the forum.
In the attached file, please click on the button New Day, once the form appeared click on the button " Load Last Day" and see the result: the list boxes autoselected the employees, machinery, etc. of the last day compiled.
The code works fine but ...
my goal would be to go back of one day for each click of the button "Load Last Day" and autoselect the correspondig employees, machinery,ecc.
This is beyond my capabilities:dunno

Thanks in advance for any help

Rayman
09-19-2011, 03:04 AM
Any ideas guys?

And first of all: its feasible?

Rayman
09-19-2011, 08:29 AM
Well, i solved the problem myself , adapting a piece of code written by p45cal in response to a my previous request for help.

For anyone interested here is the code

Dim oCell
Dim MyValue
Dim ciclo As Integer
Dim numrigaCantieri As Integer
Static FirstRowUsed As Long
Dim LastRowUsed As Long
Dim Tmp

With ActiveSheet
numrigaCantieri = Cells(Rows.Count, 15).End(xlUp).Row

If numrigaCantieri > 3 Then
If FirstRowUsed < 4 Then
FirstRowUsed = numrigaCantieri
LastRowUsed = numriga 'numriga=activesheet.CurrentRegion.Rows.Count (variable measured before in the code)

Else
If Cells(FirstRowUsed - 1, 15).Text <> "" Then
FirstRowUsed = FirstRowUsed - 1

Else
Tmp = Cells(FirstRowUsed - 1, 15).End(xlUp).Row
FirstRowUsed = Tmp
LastRowUsed = Cells(FirstRowUsed, 15).End(xlDown).Row - 1
End If
End If
End If
End With
On Error GoTo GestErr2
GestErr2:
If Err.Number = 1004 And LastRowUsed = 0 Then
MsgBox "Fine giorni precedenti!", vbExclamation
Exit Sub
End If
With cmbPersonale
For Each oCell In ActiveSheet.Range("C" & FirstRowUsed, "C" & LastRowUsed)
If oCell.Value <> "" Then MyValue = oCell.Value
For ciclo = 0 To cmbPersonale.ListCount - 1
If cmbPersonale.List(ciclo) = MyValue Then
cmbPersonale.Selected(ciclo) = True
End If
Next
Next
'etc, etc.....
End With