Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
ALP
 
Posts: n/a
Default excel Marco question ... need help please

Good afternoon all,

I am having a problem converting a marco to a command button. When I run
this marco .... TOOLS, MARCO, MACROS..., (name).. RUN , the marco runs
correct. When I copy clip the marco to the View Code in the command button,
it does not work. Below is a attached file that might be able to explain it
better. Please help, or what can I do to fix.

Thanks,
ALP

This is what I have in the accutal MARCO. (this works, when I run the marco)

Dim myRange As Range
Set myRange = Worksheets("Work").Range("L1")

If myRange = 1 Then

Range("R4:R36").Select
Selection.Copy
Sheets("QDATA").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=1
Sheets("WORK").Select
ActiveWorkbook.SAVE
Range("A2").End(xlUp).Select

ElseIf myRange = 2 Then

Range("R4:R36").Select
Selection.Copy
Sheets("QDATA").Select
Range("D4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=1
Sheets("WORK").Select
ActiveWorkbook.SAVE
Range("A2").End(xlUp).Select

This is what happens when I try to set this marco to be on my
CommandButton1. (doesnt work)

Private Sub CommandButton1_Click()

Dim myRange As Range
Set myRange = Worksheets("Work").Range("L1")

If myRange = 1 Then

Range("R4:R36").Select
Selection.Copy
Sheets("QDATA").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=1
Sheets("WORK").Select
ActiveWorkbook.SAVE
Range("A2").End(xlUp).Select


ElseIf myRange = 2 Then

Range("R4:R36").Select
Selection.Copy
Sheets("QDATA").Select
Range("D4").Select ................ this is what is highlighted as error
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=1
Sheets("WORK").Select
ActiveWorkbook.SAVE
Range("A2").End(xlUp).Select


My error message is:

Run-Time error '1004':
Select Method of Range class failed.
  #2   Report Post  
Dave O
 
Posts: n/a
Default

Try creating your button from the Forms toolbar, rather than the Visual
Basic toolbar. When you create the button from the Forms toolbar
you'll get the option to assign a macro to it.

  #3   Report Post  
Mohamed Shafiee
 
Posts: n/a
Default

Hi ALP

I tried your code and it executes well in a command button as well as a
toolbar button.

Shafiee.

"ALP" wrote in message
...
Good afternoon all,

I am having a problem converting a marco to a command button. When I run
this marco .... TOOLS, MARCO, MACROS..., (name).. RUN , the marco runs
correct. When I copy clip the marco to the View Code in the command

button,
it does not work. Below is a attached file that might be able to explain

it
better. Please help, or what can I do to fix.

Thanks,
ALP

This is what I have in the accutal MARCO. (this works, when I run the

marco)

Dim myRange As Range
Set myRange = Worksheets("Work").Range("L1")

If myRange = 1 Then

Range("R4:R36").Select
Selection.Copy
Sheets("QDATA").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=1
Sheets("WORK").Select
ActiveWorkbook.SAVE
Range("A2").End(xlUp).Select

ElseIf myRange = 2 Then

Range("R4:R36").Select
Selection.Copy
Sheets("QDATA").Select
Range("D4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=1
Sheets("WORK").Select
ActiveWorkbook.SAVE
Range("A2").End(xlUp).Select

This is what happens when I try to set this marco to be on my
CommandButton1. (doesn't work)

Private Sub CommandButton1_Click()

Dim myRange As Range
Set myRange = Worksheets("Work").Range("L1")

If myRange = 1 Then

Range("R4:R36").Select
Selection.Copy
Sheets("QDATA").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=1
Sheets("WORK").Select
ActiveWorkbook.SAVE
Range("A2").End(xlUp).Select


ElseIf myRange = 2 Then

Range("R4:R36").Select
Selection.Copy
Sheets("QDATA").Select
Range("D4").Select ................ this is what is highlighted as error
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveWindow.SmallScroll Down:=1
Sheets("WORK").Select
ActiveWorkbook.SAVE
Range("A2").End(xlUp).Select


My error message is:

Run-Time error '1004':
Select Method of Range class failed.



  #4   Report Post  
ALP
 
Posts: n/a
Default

Dave,

Thank you very much for your help. This does work. I did not know how easy
is could be, I guess I was trying to do too much with it.

Thanks again,
ALP

"Dave O" wrote:

Try creating your button from the Forms toolbar, rather than the Visual
Basic toolbar. When you create the button from the Forms toolbar
you'll get the option to assign a macro to it.


Reply
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
How do I isolate my Excel server (automation) from other Excel instances? Joseph Geretz Excel Discussion (Misc queries) 5 July 19th 13 03:18 PM
Excel chart-y axis title question springwinterfall Excel Discussion (Misc queries) 6 July 18th 05 02:27 PM
Excel 2000 file when opened in Excel 2003 generates errors? Doug Excel Discussion (Misc queries) 13 December 25th 04 10:20 PM
Macro in Excel 2002 to save a workbook to a FTP location Lloyd Excel Discussion (Misc queries) 0 December 21st 04 02:49 PM
Statistical Excel Function Question within Excel 2000... Drew H Excel Worksheet Functions 3 October 31st 04 06:55 PM


All times are GMT +1. The time now is 04:12 AM.

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

About Us

"It's about Microsoft Excel"