Share via

Problems with VBA Code

Anonymous
2018-12-12T13:48:06+00:00

Hello,

i use for copy & paste a worksheet the following Code:

 With ActiveSheet.UsedRange

        .Value = .Value

    End With

Sometime ist works, sometime i get an error "1004" on the line .Value = .Value.

It is the same file.

I copy the complete file under a  new name, but i got the same errors, sometime, sometime not.

Used with different Version (2013/2016) on different OS-Systems (Win7/Win10) and different HW (PC/TerminalClient)

Can anyone help me?

THX

Michael

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

8 answers

Sort by: Most helpful
  1. Anonymous
    2018-12-12T19:41:36+00:00

    Hello Andreas,

    nope, the same error like before..

    The same error, like my solution..

    Was this answer helpful?

    0 comments No comments
  2. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2018-12-12T17:15:35+00:00

    Please never use SELECT, SELECTION, ACTIVECELL, it is slow and error prone. Always refer to the objects directly.

    Try the code below. If you get an error 1004 at

    Set Ws = Sheets(Sheets.Count)

    add the line

    DoEvents

    before that line.

    Andreas.

    Sub Test()
      Dim Ws As Worksheet
      Sheets("Muster").Copy After:=Sheets(Sheets.Count)
      Set Ws = Sheets(Sheets.Count)
      With Ws.UsedRange
        .Value = .Value
      End With
    End Sub
    

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2018-12-12T14:24:23+00:00

    Here is more Information:

    ...

    Sheets("Muster").Select

        Sheets("Muster").Copy After:=Sheets(Sheets.Count)

    ' This convert Formula to text

        With ActiveSheet.UsedRange

            .Value = .Value

        End With

        Sheets("Muster (2)").Select

    ...

    Was this answer helpful?

    0 comments No comments
  4. Charles Kenyon 167.7K Reputation points Volunteer Moderator
    2018-12-12T14:03:11+00:00

    I'm sorry, your code makes no sense to me.

    It does not appear to do anything.

    You are setting the value equal to itself.

    Was this answer helpful?

    0 comments No comments
  5. Vijay A. Verma 104.9K Reputation points Volunteer Moderator
    2018-12-12T13:50:52+00:00

    Can you show us few more lines preceding this code so that we understand the code better?

    Was this answer helpful?

    0 comments No comments