Dim My Selection repeats

Mark Alsen

New Member
Joined
Oct 7, 2017
Messages
2
Hi Everyone.
I have a problem that if my selection is two lines or less, the two lines are repeated in the paste sheet until the sheet is full. If I select three or more lines it seems to be fine and will only paste and sort the the lines that I have selected. Can anyone help

Code:
Sub Macro4()
'
' Macro4 Macro
'


'
    Dim ws As Worksheet
    Dim mySel As Range
    Selection.Copy
    Sheets("Sheet2").Select
    Range("A5:I16").Select
    ActiveSheet.Paste
    Range("B5:H16").Sort Key1:=Range("B6:H16"), Order1:=xlAscending, Header:=xlNo
    Set keyCell = Range("B5")
    
    Range("B4:B16").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
 
        With Selection.Borders
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
    
   Rem ActiveSheet.PrintOut
    Rem Sheet2.Range("A5:I16").ClearContents
    Sheets("Sheet1").Select
    
  End With


    
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Fixed it thank anyway. I you take the selection from I16 to any column (say T) it fixes it if under three lines are selected
Regards
Mark
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top