LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Newbie needs macro help please

Glad it helped. I still don't like command buttons. Try using shapes. You
can be more creative.

--
Don Guillett
SalesAid Software

"Keith" wrote in message
...
Many thanks for the replies.

Tried both solutions. Unfortunately Anon. I got the same error with your
solution.

Don's solution copied and pasted under CommandButton1_Click()did the trick
though.

Thanks again

Keith

"Keith" wrote:

I have a file with 2 worksheets Main and Data and want to run a macro
from a Command Button in the Main worksheet which goes to the Data
worksheet, refreshes a query, parses the data and goes back to the
Main worksheet.

This is what I've done:
Recorded a macro which is Macro1 in Module1 which works if run from
Tools, Macro, Macro1, Run

Created a button which gives me Private Sub CommandButton1_Click()in
the Objects section for Sheet1 (Main)

Copied the code from Module1 Macro1 to the Sub CommandButton1_Click()

When I run the macro from the Command Button it gets to
Columns("A:A").Select and falls over with an error message "Run time
error 1004 - Select method of Range class failed.

I don't understand why it doesn't work when linked to the Command
Button when it's fine when run straight from Module1


I'd be really grateful if someone could explain whhere I'm going wrong
and how to put it right as I've spent hours looking on the net for a
solution but I think I'm out of my depth.

The code is below

Thanks a lot for your help

Keith


Private Sub CommandButton1_Click()

Worksheets("Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=True, 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),
Array(17, 1), Array(18, 1), Array( _
19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array(23,
1))
Range("A1").Select
Sheets("Main").Select
End Sub





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie: VBA? Macro? Please Advise... pollywog1961 Excel Discussion (Misc queries) 1 May 29th 06 07:57 PM
Macro newbie VB Newbie Excel Programming 3 November 12th 04 07:08 AM
VBA Newbie - Simple Macro Yeimi Excel Programming 2 April 13th 04 04:20 PM
Loop macro for a Newbie mike Excel Programming 3 December 31st 03 06:35 PM
Macro Help for Newbie Phil Excel Programming 2 October 15th 03 04:57 AM


All times are GMT +1. The time now is 09:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"