+ Reply to Thread
Results 1 to 6 of 6

Problem with copy selection during macro

  1. #1
    Registered User
    Join Date
    03-29-2018
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    7

    Question Problem with copy selection during macro

    Hi Guys
    I have a little problem here. I want to use a macro to find a number in column H that is in the copy selection and delete the row the given number is in. However when i try to run the macro, it just writes the number of the actual number that the macro was "programmed" with indstead of the number in copy selection.
    Can you help me solve this problem. Simple part of the code looks like this.
    Please Login or Register  to view this content.
    However what i would want should be like this, but i gives me an error.
    Please Login or Register  to view this content.
    Can someone please help me here
    The Macro works perfectly fine and as intended as long as i give it the number - 24 to erase - in this case. However the 24 should be anything the macro finds to delete indstead of just a 24.

    Hope somebody can help me out here
    Last edited by 6StringJazzer; 03-30-2018 at 09:38 AM. Reason: code tags

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Problem with copy selection during macro

    Please Login or Register  to view this content.
    "should be anything the macro finds to delete"??????

  3. #3
    Registered User
    Join Date
    03-29-2018
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    7

    Re: Problem with copy selection during macro

    I will try to explain.
    The first sheet is full of assignments
    The second sheet is full of orders to be filled (Products for every assignment)
    The Third sheet is full of Delivery dates.
    When the order has been filled, it gets a delivery date - hence it shall be deleted from sheet2 and posted in sheet3.
    When i programmed the macro i used copy selection of the number 24 assignment.
    The macro works absolutely as it should as long as i give it a 24 assignment to put in sheet3 and delete in sheet 2.
    However this should work with whatever number of assignment is chosen in sheet1.
    So instead of "24" in the macro it should read "copy selection". But somehow that does not work.
    Feel free to ask if you've got any more questions

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,673

    Re: Problem with copy selection during macro

    What do you mean by "copy selection"? Have you already done a copy? If so, this would be "clipboard contents". Or have you just done a selection with the intent to do a copy? If so, this would be "selection."

    Your example gives an error, of course, because it is looking for the string

    "Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False"

    which it won't find.

    Please show all of your code to give the context of what you are trying to do.

    You may find this example helpful (which I have adapted). You must set a reference to Microsoft Forms 2.0 library.
    Please Login or Register  to view this content.

    How to use:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    03-29-2018
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    7

    Re: Problem with copy selection during macro

    Hi, sorry for the late answer, been seperated from my work pc with the files for a couple of weeks.
    The entire code looks like the following:
    ' Modtaget Makro
    '
    ' Genvejstast:Ctrl+w
    -'
    - ActiveCell.Offset(0, 20).Range("A1").Select
    - ActiveCell.FormulaR1C1 = "=NOW()"
    - ActiveCell.Select
    - With Selection.Font
    - .ThemeColor = xlThemeColorDark1
    - .TintAndShade = 0
    - End With
    - Selection.Copy
    - ActiveCell.Offset(0, -20).Range("A1").Select
    - Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    - xlNone, SkipBlanks:=False, Transpose:=False
    - ActiveCell.Offset(0, -5).Range("A1:P1").Select
    - With Selection.Font
    - .Color = -4165632
    - .TintAndShade = 0
    - End With
    - Selection.Copy
    - Sheets("Sidst Opdateret").Select
    - Application.Goto Reference:="R5C1"
    - Selection.Insert Shift:=xlDown
    - ActiveCell.Select
    - Sheets("Opgave Liste").Select
    - ActiveCell.Select
    - Application.CutCopyMode = False
    - ActiveCell.Rows("1:1").EntireRow.Select
    - Selection.Copy
    - Sheets("Til Montering").Select
    - Application.Goto Reference:="R3C1"
    - ActiveCell.Rows("1:1").EntireRow.Select
    - Selection.Insert Shift:=xlDown
    - Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    - xlNone, SkipBlanks:=False, Transpose:=False
    - ActiveCell.Offset(0, 7).Range("A1").Select
    - Application.CutCopyMode = False
    - Selection.Copy
    - Sheets("Til Levering").Select
    - Application.Goto Reference:="R1C8"
    - Cells.Find(What:="24", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    - xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    - False, SearchFormat:=False).Activate
    - ActiveCell.Rows("1:1").EntireRow.Select
    - Application.CutCopyMode = False
    - Selection.Delete Shift:=xlUp
    - ActiveCell.Select
    - Sheets("Til Montering").Select
    - ActiveWorkbook.Worksheets("Til Montering").Sort.SortFields.Clear
    - ActiveWorkbook.Worksheets("Til Montering").Sort.SortFields.Add Key:= _
    - ActiveCell.Range("A1:A9"), SortOn:=xlSortOnValues, Order:=xlAscending, _
    - DataOption:=xlSortNormal
    - With ActiveWorkbook.Worksheets("Til Montering").Sort
    - .SetRange ActiveCell.Offset(-1, -7).Range("A1:L11")
    - .Header = xlYes
    - .MatchCase = False
    - .Orientation = xlTopToBottom
    - .SortMethod = xlPinYin
    - .Apply
    - End With
    - ActiveCell.Offset(0, -7).Range("A1").Select
    - Sheets("Opgave Liste").Select
    - ActiveCell.Select
    - Application.Goto Reference:="R2C2"
    - Selection.Copy
    - ActiveCell.Offset(1, 0).Range("A1").Select
    - Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    - xlNone, SkipBlanks:=False, Transpose:=False
    - ActiveCell.Offset(-1, -1).Range("A1").Select
    - Application.CutCopyMode = False
    -End Sub
    Last edited by noes75; 04-14-2018 at 07:25 AM.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,673

    Re: Problem with copy selection during macro

    I helped you on your first post but now I am going to have to insist that you post your code with code tags.

    Your post does not comply with Rule 3 of our Forum Rules: Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Problem with Macro to copy and paste a selection
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-14-2017, 02:04 PM
  2. [SOLVED] VBA problem with selection/copy specified range of cells
    By sauron1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-07-2017, 10:27 AM
  3. [SOLVED] Copy And Paste Range on diffrenct sheet Selection problem Solved by : sixthsense
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-02-2014, 03:43 AM
  4. Problem with Selection find, offset, copy & paste Macro
    By MDResearcher in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 06-21-2011, 05:51 PM
  5. range selection problem to copy data from 1 sheet to another
    By apoo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2011, 02:55 AM
  6. Problem with Range,Selection, Copy and Paste
    By ljunggrenus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2007, 07:19 AM
  7. Text selection macro problem
    By djstriker91 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-06-2005, 05:05 AM

Tags for this Thread

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