View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default "run-time error '1004' - select method of range failed"

Hi,

You code up to and including the part you say doesn't work is fine so
provided the workbook you open has a worksheet with the same name picked in
the select case statement then it selects A4 - A60 of that sheet.

After that your code becomes a bit odd in that you seem to be selecting
ranges and doing nothing. In fact it's not obvious why you select A4 - A60
because your next commented out line would select A4 so perhaps you could
explain what you would like to happen.

Mike

"maemi weirdoke" wrote:

Hello all,

I have a similar question.

Basically the macro got stuck at this point: ****


Private Sub get_holi_data_Click()

Dim sFileName As String 'gives file
Dim teller1 As Integer
Dim tmp1 As String
Dim datemonth As Integer
Dim datename As String

'Sorts out which month sheet you want
datemonth = Range("E1:E1").Value

Select Case datemonth
Case Is = 1
datename = "January"
Case Is = 2
datename = "February"
Case Is = 3
datename = "March"
Case Is = 4
datename = "April"
Case Is = 5
datename = "May"
Case Is = 6
datename = "June"
Case Is = 7
datename = "July"
Case Is = 8
datename = "August"
Case Is = 9
datename = "September"
Case Is = 10
datename = "October"
Case Is = 11
datename = "November"
Case Is = 12
datename = "December"
End Select

' Import data from holiday

sFileName = Application.GetOpenFilename("Microsoft Excel Files (*.xls),
*.xls")
If sFileName < "False" Then

Workbooks.Open sFileName, UpdateLinks:=3
Sheets(datename).Select 'works
Range("A4:A60").Select 'stuck here ****
'Range("A4:A4").Select
'MsgBox Range("A4:A4").Select
'Range("A4:A4").Activate
'Range("A60").Activate
' Selection.Copy
Windows("test.xls").Activate 'activate this worksheet --works
Sheets("Temp").Select 'works
'Columns("A:A").Select
'Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
' True, Transpose:=False
Windows(docname).Activate 'works
ActiveWindow.Close 'works

Else
MsgBox ("Please provide a valid holiday xls. document")
End If

End Sub

As I only have "basic" knowledge of VB.net, maybe you can help me out
here?
Any help is much appreciated with of course a little explanation.

*** Sent via Developersdex http://www.developersdex.com ***