HEALTHSTAFF
New Member
- Joined
- Oct 5, 2017
- Messages
- 12
hello,
I have a spreadsheet that is basically a roster that staff can choose to print just their own shifts.
The code below runs with no errors popping up but there is always no results shown.
The input is via userform list box with command button. (I have not used user forms before)
It seems to copy the list value and places in worksheet 1 OK but then doesn't seem to find the staff name. The font, size, spelling and no spaces are identical. so I don't know why it can find items.
The coding is a bit basic (Noob) and i have cobbled it together from old spreadsheets and Google. Could i trouble a guru to have a look and see if i am missing something obvious?
Many Thanks and please be gentle
'Private Sub CommandButton1_Click()
Step1
Step2
End Sub
Private Sub Step1()
Worksheets("Sheet3").Range("1:100").EntireRow.Hidden = False
Worksheets("Sheet3").Range("C4:P100").ClearContents
Application.ScreenUpdating = False
Worksheets("Sheet1").Select
Dim listItems As String, i As Long
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then listItems = listItems & .List(i) & ""
Next i
End With
If Len(listItems) > 0 Then
Range("A1") = Left(listItems, Len(listItems) - 0)
Else
Range("A1") = ""
End If
End Sub
Private Sub Step2()
Dim c As Range
Dim ans As String
Dim anss As Variant
ans = Range("Sheet1!A1")
For Each c In Worksheets("Sheet1").Range("C4:P100")
If c.Value = ans Then
anss = c.Address
Sheets(3).Range(anss).Value = ans
End If
Next
Application.Calculation = xlCalculationManual
Set r = Worksheets("Sheet3").Range("C4:P100")
Application.ScreenUpdating = False
ActiveSheet.Rows.Hidden = False
r.EntireRow.Hidden = True
For Each c In r
If c <> Blank Then
c.EntireRow.Hidden = False
End If
Next c
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Worksheets("Sheet3").Activate
Application.Dialogs(xlDialogPrint).Show
Worksheets("Sheet3").Range("1:100").EntireRow.Hidden = False
Worksheets("Sheet3").Range("C4:P100").ClearContents
Worksheets("Sheet1").Activate
MsgBox ("STAFF PLEASE CHECK YOUR PRINTED ROSTER WITH ORIGINAL"), vbExclamation
Exit Sub
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub'
I have a spreadsheet that is basically a roster that staff can choose to print just their own shifts.
The code below runs with no errors popping up but there is always no results shown.
The input is via userform list box with command button. (I have not used user forms before)
It seems to copy the list value and places in worksheet 1 OK but then doesn't seem to find the staff name. The font, size, spelling and no spaces are identical. so I don't know why it can find items.
The coding is a bit basic (Noob) and i have cobbled it together from old spreadsheets and Google. Could i trouble a guru to have a look and see if i am missing something obvious?
Many Thanks and please be gentle
'Private Sub CommandButton1_Click()
Step1
Step2
End Sub
Private Sub Step1()
Worksheets("Sheet3").Range("1:100").EntireRow.Hidden = False
Worksheets("Sheet3").Range("C4:P100").ClearContents
Application.ScreenUpdating = False
Worksheets("Sheet1").Select
Dim listItems As String, i As Long
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then listItems = listItems & .List(i) & ""
Next i
End With
If Len(listItems) > 0 Then
Range("A1") = Left(listItems, Len(listItems) - 0)
Else
Range("A1") = ""
End If
End Sub
Private Sub Step2()
Dim c As Range
Dim ans As String
Dim anss As Variant
ans = Range("Sheet1!A1")
For Each c In Worksheets("Sheet1").Range("C4:P100")
If c.Value = ans Then
anss = c.Address
Sheets(3).Range(anss).Value = ans
End If
Next
Application.Calculation = xlCalculationManual
Set r = Worksheets("Sheet3").Range("C4:P100")
Application.ScreenUpdating = False
ActiveSheet.Rows.Hidden = False
r.EntireRow.Hidden = True
For Each c In r
If c <> Blank Then
c.EntireRow.Hidden = False
End If
Next c
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Worksheets("Sheet3").Activate
Application.Dialogs(xlDialogPrint).Show
Worksheets("Sheet3").Range("1:100").EntireRow.Hidden = False
Worksheets("Sheet3").Range("C4:P100").ClearContents
Worksheets("Sheet1").Activate
MsgBox ("STAFF PLEASE CHECK YOUR PRINTED ROSTER WITH ORIGINAL"), vbExclamation
Exit Sub
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub'