+ Reply to Thread
Results 1 to 8 of 8

Paste Special

  1. #1
    Forum Contributor
    Join Date
    11-23-2004
    Location
    Bristol
    MS-Off Ver
    2016
    Posts
    225

    Smile Paste Special

    Hi all, I have some code below that another user kindly provided but would ask if anybody could help me with a slight modification - the code will copy and paste special a range from one worksheet to another worksheet and works great - but I have had some items that start with zero's in the origin and after the paste special ( because I only want values and not formula's to copy ) will convert say '012345 to 12345 but I do need the '012345 to be displayed as it is - any suggestions will be kindly received.

    Dim sourceRange As Range
    Dim destrange As Range
    Dim Lr As Long
    Lr = LastRow(Sheets("Worksheet1")) + 1
    Set sourceRange = Sheets("Worksheet2").Range("BO7:CZ21")
    With sourceRange
    Set destrange = Sheets("Worksheet1").Range("A" & Lr). _
    Resize(.Rows.Count, .Columns.Count)
    End With
    destrange.Value = sourceRange.Value
    End Sub

    Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
    After:=sh.Range("A1"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Row
    On Error GoTo 0
    End Function

    Function Lastcol(sh As Worksheet)
    On Error Resume Next
    Lastcol = sh.Cells.Find(What:="*", _
    After:=sh.Range("A1"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByColumns, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Column
    On Error GoTo 0
    End Function

  2. #2
    Forum Contributor
    Join Date
    11-23-2004
    Location
    Bristol
    MS-Off Ver
    2016
    Posts
    225

    Smile Paste Special

    Hi all, I have some code below that another user kindly provided but would ask if anybody could help me with a slight modification - the code will copy and paste special a range from one worksheet to another worksheet and works great - but I have had some items that start with zero's in the origin and after the paste special ( because I only want values and not formula's to copy ) will convert say '012345 to 12345 but I do need the '012345 to be displayed as it is - any suggestions will be kindly received.

    Dim sourceRange As Range
    Dim destrange As Range
    Dim Lr As Long
    Lr = LastRow(Sheets("Worksheet1")) + 1
    Set sourceRange = Sheets("Worksheet2").Range("BO7:CZ21")
    With sourceRange
    Set destrange = Sheets("Worksheet1").Range("A" & Lr). _
    Resize(.Rows.Count, .Columns.Count)
    End With
    destrange.Value = sourceRange.Value
    End Sub

    Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
    After:=sh.Range("A1"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Row
    On Error GoTo 0
    End Function

    Function Lastcol(sh As Worksheet)
    On Error Resume Next
    Lastcol = sh.Cells.Find(What:="*", _
    After:=sh.Range("A1"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByColumns, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Column
    On Error GoTo 0
    End Function

  3. #3
    Gary''s Student
    Guest

    RE: Paste Special

    Looking at:

    destrange.Value = sourceRange.Value

    you can test for the single quote and insure that it gets copied over:

    Sub gsnu()
    Dim r1, r2 As Range
    Set r1 = Range("A1")
    Set r2 = Range("A2")
    If r1.PrefixCharacter = "'" Then
    r2.Value = Chr(39) & r1.Value
    Else
    r2.Value = r1.Value
    End If
    End Sub


    You need to take this special step to preserve the single quote because

    something.value=something.value

    is a standard way of removing single quotes.
    --
    Gary's Student


    "sparx" wrote:

    >
    > Hi all, I have some code below that another user kindly provided but
    > would ask if anybody could help me with a slight modification - the
    > code will copy and paste special a range from one worksheet to another
    > worksheet and works great - but I have had some items that start with
    > zero's in the origin and after the paste special ( because I only want
    > values and not formula's to copy ) will convert say '012345 to 12345
    > but I do need the '012345 to be displayed as it is - any suggestions
    > will be kindly received.
    >
    > Dim sourceRange As Range
    > Dim destrange As Range
    > Dim Lr As Long
    > Lr = LastRow(Sheets("Worksheet1")) + 1
    > Set sourceRange = Sheets("Worksheet2").Range("BO7:CZ21")
    > With sourceRange
    > Set destrange = Sheets("Worksheet1").Range("A" & Lr). _
    > Resize(.Rows.Count, .Columns.Count)
    > End With
    > destrange.Value = sourceRange.Value
    > End Sub
    >
    > Function LastRow(sh As Worksheet)
    > On Error Resume Next
    > LastRow = sh.Cells.Find(What:="*", _
    > After:=sh.Range("A1"), _
    > Lookat:=xlPart, _
    > LookIn:=xlFormulas, _
    > SearchOrder:=xlByRows, _
    > SearchDirection:=xlPrevious, _
    > MatchCase:=False).Row
    > On Error GoTo 0
    > End Function
    >
    > Function Lastcol(sh As Worksheet)
    > On Error Resume Next
    > Lastcol = sh.Cells.Find(What:="*", _
    > After:=sh.Range("A1"), _
    > Lookat:=xlPart, _
    > LookIn:=xlFormulas, _
    > SearchOrder:=xlByColumns, _
    > SearchDirection:=xlPrevious, _
    > MatchCase:=False).Column
    > On Error GoTo 0
    > End Function
    >
    >
    > --
    > sparx
    > ------------------------------------------------------------------------
    > sparx's Profile: http://www.excelforum.com/member.php...o&userid=16787
    > View this thread: http://www.excelforum.com/showthread...hreadid=551639
    >
    >


  4. #4
    Forum Contributor
    Join Date
    11-23-2004
    Location
    Bristol
    MS-Off Ver
    2016
    Posts
    225

    Paste Special

    Hi there, being dum as I am, where would I place your code in the code I already have?

  5. #5
    Gary''s Student
    Guest

    Re: Paste Special

    replace:

    destrange.Value = sourceRange.Value


    with:

    If sourceRange.PrefixCharacter = "'" Then
    destrange.Value = Chr(39) & sourceRange.Value
    Else
    destrange.Value = sourceRange.Value
    End If

    --
    Gary's Student


    "sparx" wrote:

    >
    > Hi there, being dum as I am, where would I place your code in the code I
    > already have?
    >
    >
    > --
    > sparx
    > ------------------------------------------------------------------------
    > sparx's Profile: http://www.excelforum.com/member.php...o&userid=16787
    > View this thread: http://www.excelforum.com/showthread...hreadid=551639
    >
    >


  6. #6
    Jim Cone
    Guest

    Re: Paste Special

    Add this line...
    destrange.NumberFormat = "@"
    just before this line...
    destrange.Value = sourceRange.Value
    --
    Jim Cone
    San Francisco, USA
    http://www.realezsites.com/bus/primitivesoftware


    "sparx"
    <[email protected]>
    wrote in message
    Hi all, I have some code below that another user kindly provided but
    would ask if anybody could help me with a slight modification - the
    code will copy and paste special a range from one worksheet to another
    worksheet and works great - but I have had some items that start with
    zero's in the origin and after the paste special ( because I only want
    values and not formula's to copy ) will convert say '012345 to 12345
    but I do need the '012345 to be displayed as it is - any suggestions
    will be kindly received.

    Dim sourceRange As Range
    Dim destrange As Range
    Dim Lr As Long
    Lr = LastRow(Sheets("Worksheet1")) + 1
    Set sourceRange = Sheets("Worksheet2").Range("BO7:CZ21")
    With sourceRange
    Set destrange = Sheets("Worksheet1").Range("A" & Lr). _
    Resize(.Rows.Count, .Columns.Count)
    End With
    destrange.Value = sourceRange.Value
    End Sub

    Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
    After:=sh.Range("A1"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Row
    On Error GoTo 0
    End Function

    Function Lastcol(sh As Worksheet)
    On Error Resume Next
    Lastcol = sh.Cells.Find(What:="*", _
    After:=sh.Range("A1"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByColumns, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Column
    On Error GoTo 0
    End Function

  7. #7
    JMB
    Guest

    RE: Paste Special

    Instead of

    destrange.Value = sourceRange.Value

    try

    sourceRange.Copy destrange

    Does that help?

    "sparx" wrote:

    >
    > Hi all, I have some code below that another user kindly provided but
    > would ask if anybody could help me with a slight modification - the
    > code will copy and paste special a range from one worksheet to another
    > worksheet and works great - but I have had some items that start with
    > zero's in the origin and after the paste special ( because I only want
    > values and not formula's to copy ) will convert say '012345 to 12345
    > but I do need the '012345 to be displayed as it is - any suggestions
    > will be kindly received.
    >
    > Dim sourceRange As Range
    > Dim destrange As Range
    > Dim Lr As Long
    > Lr = LastRow(Sheets("Worksheet1")) + 1
    > Set sourceRange = Sheets("Worksheet2").Range("BO7:CZ21")
    > With sourceRange
    > Set destrange = Sheets("Worksheet1").Range("A" & Lr). _
    > Resize(.Rows.Count, .Columns.Count)
    > End With
    > destrange.Value = sourceRange.Value
    > End Sub
    >
    > Function LastRow(sh As Worksheet)
    > On Error Resume Next
    > LastRow = sh.Cells.Find(What:="*", _
    > After:=sh.Range("A1"), _
    > Lookat:=xlPart, _
    > LookIn:=xlFormulas, _
    > SearchOrder:=xlByRows, _
    > SearchDirection:=xlPrevious, _
    > MatchCase:=False).Row
    > On Error GoTo 0
    > End Function
    >
    > Function Lastcol(sh As Worksheet)
    > On Error Resume Next
    > Lastcol = sh.Cells.Find(What:="*", _
    > After:=sh.Range("A1"), _
    > Lookat:=xlPart, _
    > LookIn:=xlFormulas, _
    > SearchOrder:=xlByColumns, _
    > SearchDirection:=xlPrevious, _
    > MatchCase:=False).Column
    > On Error GoTo 0
    > End Function
    >
    >
    > --
    > sparx
    > ------------------------------------------------------------------------
    > sparx's Profile: http://www.excelforum.com/member.php...o&userid=16787
    > View this thread: http://www.excelforum.com/showthread...hreadid=551652
    >
    >


  8. #8
    Forum Contributor
    Join Date
    11-23-2004
    Location
    Bristol
    MS-Off Ver
    2016
    Posts
    225

    Paste Special

    I will try both methods you describe.

+ 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