K
ksnapp
Hello,
I need to add a function to the sub and don't know how to start.
It asks you to input the name of a workbook, then it asks if that
really the one you want. I need somethin after that that checks to se
if that requested workbook is open and if it is NOT stops the code an
tell the user to open the specified workbook.
also, this code works well, but I think it might be bette
accomplished than the way I did it. If any body has some ideas on ho
i could improve it I would appreciated it.
Sub data_geter()
Dim dates As New Collection
Dim yesno As New Collection
Dim days As New Collection
Dim data As New Collection
Dim collen As New Collection
Dim rnghold As Range
Dim rng As Range
Dim A As Range
Dim findme As Variant
Dim book As String
Dim TR As Single
Dim SR As Single
Dim daysCNT As Single
Dim DN As Single
Dim FN As Single
Dim SN As Single
Dim i As Single
Dim LN As Single
Dim correct As Single
Dim y As Byte
Workbooks("Book1.xls").Activate
book = Application.InputBox(PRompt:="Paste the name of source data"
Title:="What book are we using this time?", Type:=2)
correct = MsgBox(PRompt:=book, Buttons:=4, Title:="Is This Nam
Correct")
If correct = 7 Then
Exit Sub
End If
Set A = Application.InputBox(PRompt:="Select the Dates to copy for"
Type:=8)
A.Select
With Selection
daysCNT = A.Columns.Count
Set rnghold = Selection
For Each cell In rnghold
dates.Add (cell)
FN = Application.WorksheetFunction.Find("/", cell, 1)
SN = Application.WorksheetFunction.Find("/", cell, FN + 1)
DN = Mid(cell, FN + 1, SN - FN - 1)
days.Add (DN)
Next
End With
With days
For i = 1 To daysCNT Step 1
y = 0
Workbooks(book).Activate
Worksheets(days(i)).Select
TR = Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range("a1", Cells(TR / 2, 1))
With rng
findme = "7:30"
rng.Find(what:=findme, LookIn:=xlValues).Select
On Error Resume Next
findme = "7:00"
.Find(what:=findme, LookIn:=xlValues).Select
SR = Selection.Row
If Format(Selection.Value, "H:MM") = "7:30" Then
y = 1
Else
y = 0
End If
On Error GoTo 0
data.Add (Range(Cells(SR, 6), Cells(TR, 6)))
LN = TR - SR
collen.Add (LN)
yesno.Add (y)
End With
Next i
End With
Workbooks("Book1.xls").Activate
With rnghold
For Each cell In rnghold
For i = 1 To daysCNT Step 1
If cell.Value = dates(i) Then
Range(cell.Offset(4 + yesno(i), 0), cell.Offset(collen(i) + 4
0)).Value = data(i)
End If
Next
Next
End With
End Sub
Thank Yo
I need to add a function to the sub and don't know how to start.
It asks you to input the name of a workbook, then it asks if that
really the one you want. I need somethin after that that checks to se
if that requested workbook is open and if it is NOT stops the code an
tell the user to open the specified workbook.
also, this code works well, but I think it might be bette
accomplished than the way I did it. If any body has some ideas on ho
i could improve it I would appreciated it.
Sub data_geter()
Dim dates As New Collection
Dim yesno As New Collection
Dim days As New Collection
Dim data As New Collection
Dim collen As New Collection
Dim rnghold As Range
Dim rng As Range
Dim A As Range
Dim findme As Variant
Dim book As String
Dim TR As Single
Dim SR As Single
Dim daysCNT As Single
Dim DN As Single
Dim FN As Single
Dim SN As Single
Dim i As Single
Dim LN As Single
Dim correct As Single
Dim y As Byte
Workbooks("Book1.xls").Activate
book = Application.InputBox(PRompt:="Paste the name of source data"
Title:="What book are we using this time?", Type:=2)
correct = MsgBox(PRompt:=book, Buttons:=4, Title:="Is This Nam
Correct")
If correct = 7 Then
Exit Sub
End If
Set A = Application.InputBox(PRompt:="Select the Dates to copy for"
Type:=8)
A.Select
With Selection
daysCNT = A.Columns.Count
Set rnghold = Selection
For Each cell In rnghold
dates.Add (cell)
FN = Application.WorksheetFunction.Find("/", cell, 1)
SN = Application.WorksheetFunction.Find("/", cell, FN + 1)
DN = Mid(cell, FN + 1, SN - FN - 1)
days.Add (DN)
Next
End With
With days
For i = 1 To daysCNT Step 1
y = 0
Workbooks(book).Activate
Worksheets(days(i)).Select
TR = Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range("a1", Cells(TR / 2, 1))
With rng
findme = "7:30"
rng.Find(what:=findme, LookIn:=xlValues).Select
On Error Resume Next
findme = "7:00"
.Find(what:=findme, LookIn:=xlValues).Select
SR = Selection.Row
If Format(Selection.Value, "H:MM") = "7:30" Then
y = 1
Else
y = 0
End If
On Error GoTo 0
data.Add (Range(Cells(SR, 6), Cells(TR, 6)))
LN = TR - SR
collen.Add (LN)
yesno.Add (y)
End With
Next i
End With
Workbooks("Book1.xls").Activate
With rnghold
For Each cell In rnghold
For i = 1 To daysCNT Step 1
If cell.Value = dates(i) Then
Range(cell.Offset(4 + yesno(i), 0), cell.Offset(collen(i) + 4
0)).Value = data(i)
End If
Next
Next
End With
End Sub
Thank Yo