does anyone see what is wrong with this code

ecoscientist

New Member
Joined
Apr 4, 2002
Messages
12
I keep getting a "subscript out of range error" in the following piece of code. It was working fine and then suddenly started crashing. I don't see anything wrong.

Sub opentextfile()
' this routine opens a file in text format identified with the variable FILENAME!

Workbooks.OpenText FileName:=(guess & UserForm4.ListBox1), Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1))
'copy file into rawdata sheet
Range("A1:I274").Copy Destination:=Workbooks("project.xls").Sheets("RAW_DATA").Range("A1").End(xlUp)
ActiveWindow.Close ([True])
' Copy area counts column and paste it into correct instrument and level transpose it to a row
sheetselect = ("gc3_RF") 'this is added here for trouble shooting only remove when fixed

Workbooks("project.XLS").Activate
Sheets("RAW_DATA").Range("f4:f18").Copy
Sheets(sheetselect).Activate 'error occurs here
Cells(numit + 3, 2).Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
Application.CutCopyMode = False
ActiveWorkbook.Save



End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
thanks, that seemed to work I still don't know why this suddenly became an issue have been usingthis code for a while.
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top