Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running code for formatting 1 s/s from a cmd button on another sheet??

Status
Not open for further replies.

VictoriaJones

Technical User
Apr 5, 2002
9
US
Hi,

I have written a macro (which is stored in an individual workbook) which runs correctly when using the "Tools/Macro/Macros/Run" tool-bar, however I want to assign this code to a command button.

When I do this however I get an error message: "Run Time Error 1004. Select method of Range class failed " At the:
"Rows("1:1").Select"
point in the following code:

Application.ScreenUpdating = False
Workbooks.OpenText FileName:="U:\bu-del-buyet.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True, OtherChar:="|", FieldInfo:=Array(Array(1, 1 _
), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
, 1), Array(16, 1))
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select

etc......

Is this because the cmd button I am using is generating and formatting another workbook? I have tried using the "Workbooks("....").Activate code before the Select Rows code (using the new workbooks temp name that excel generates when it creates it from the txt file), but this does not make any difference to the error.

If anyone can see the flaw/problem please help!!

Thanks
Victoria
 
Try replacing

Rows("1:1").Select
Selection.Insert Shift:=xlDown

with

ActiveSheet.Cells(1).EntireRow.Insert

A.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top