+ Reply to Thread
Results 1 to 3 of 3

Excel MARCO help....

  1. #1
    Registered User
    Join Date
    01-13-2005
    Posts
    21

    Excel MARCO help....

    Good morning 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
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello ALP,

    What is the error message you are getting?

    Thanks,
    Leith Ross

  3. #3
    Registered User
    Join Date
    01-13-2005
    Posts
    21
    The error message that I am getting is:

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

    Thanks,
    ALP

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1