L
Lee Hunter
This sub was working just fine when the code was in the
workbook that contained the data. Now that I moved it
and use the "GetOpenFile" function to get the data sheet,
I get Run Time Error (1004) on the line beginning with
*********.
Does anyone see the problem?
Thanks for all your help.
Private Sub TextBox1_Change()
Dim MyRange As Range, answer, mess, startR As Range, endR
As Range, MRange As Range
NewFN = Application.GetOpenFilename(FileFilter:="Excel
Files (*.xls), *.xls", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
Worksheets("No Stock Log-Daily").Range("a7").Activate
Set MyRange = Range("a7")
answer = 0
Do Until answer = 1
If IsEmpty(ActiveCell.Value) Then
answer = 1
End If
ActiveCell.Offset(1, 0).Select
Loop
Set endR = ActiveCell
*********** Set MRange = Range(MyRange, endR)******
With Worksheets("No Stock Log-Daily").Range(MRange)
Set c = .Find("wave", LookIn:=xlValues,
LookAt:=xlPart)
If Not c Is Nothing Then
firstAddress = c.Address
d = c.Row
d = d - 1
Set startR = Range("L1")
Set startR = startR.Offset(d, 0)
Set endR = endR.Offset(0, 11)
With Worksheets("No Stock Log-Daily").Range
(startR, endR)
Set MRange = startR
Do While MRange.Row < endR.Row
If MRange.MergeCells Then
MRange.MergeArea.UnMerge
End If
Set MRange = MRange.Offset(1, 0)
Loop
Set MyRange = Range(startR, MRange)
answer = Application.WorksheetFunction.SumIf
(MyRange, ">0")
MsgBox "The number of No Stock events is = "
& answer
End With
End If
End With
End Sub
workbook that contained the data. Now that I moved it
and use the "GetOpenFile" function to get the data sheet,
I get Run Time Error (1004) on the line beginning with
*********.
Does anyone see the problem?
Thanks for all your help.
Private Sub TextBox1_Change()
Dim MyRange As Range, answer, mess, startR As Range, endR
As Range, MRange As Range
NewFN = Application.GetOpenFilename(FileFilter:="Excel
Files (*.xls), *.xls", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
Worksheets("No Stock Log-Daily").Range("a7").Activate
Set MyRange = Range("a7")
answer = 0
Do Until answer = 1
If IsEmpty(ActiveCell.Value) Then
answer = 1
End If
ActiveCell.Offset(1, 0).Select
Loop
Set endR = ActiveCell
*********** Set MRange = Range(MyRange, endR)******
With Worksheets("No Stock Log-Daily").Range(MRange)
Set c = .Find("wave", LookIn:=xlValues,
LookAt:=xlPart)
If Not c Is Nothing Then
firstAddress = c.Address
d = c.Row
d = d - 1
Set startR = Range("L1")
Set startR = startR.Offset(d, 0)
Set endR = endR.Offset(0, 11)
With Worksheets("No Stock Log-Daily").Range
(startR, endR)
Set MRange = startR
Do While MRange.Row < endR.Row
If MRange.MergeCells Then
MRange.MergeArea.UnMerge
End If
Set MRange = MRange.Offset(1, 0)
Loop
Set MyRange = Range(startR, MRange)
answer = Application.WorksheetFunction.SumIf
(MyRange, ">0")
MsgBox "The number of No Stock events is = "
& answer
End With
End If
End With
End Sub