using error line

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a macro that adds a blank line to a row of dates. (to separate each row)
When it gets to the end, I get an error message.
I tried to add an ERROR LINE, but I’m doing something wrong
When it gets to the last line it gives me an error message I thing since >>End(xlDown) takes it to the bottom of the sheet .
I am using a looping macro to start it
VBA Code:
Sub newmultiplefills() 
Dim I
For I = 1 To Range("dates")
    Macro3
Next I
errorline: Exit Sub
End Sub
VBA Code:
Sub Macro3()
On Error GoTo errorline
    ActiveCell.Range("A1:B1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Cut
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(1, 0).Range("A1").Select
errorline:     Exit Sub
End Sub

mike
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Is this what you want ?

VBA Code:
Sub newmultiplefills()
    Dim r As Long, c As Long
    c = ActiveCell.Column
    r = ActiveCell.Row
    For r = r - 1 + [dates] To r Step -1
        Cells(r, c).Resize(, 2).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Next r
End Sub
 
Upvote 0
Hi Yongle
Hope your well
Yep that'll work just fine. Sure is a lot neater than what i had

Just wondering.....it stops after about 15 rows. when I had about 30 rows to separate . I don't see where that is in the code
Can I increase or decrease it??

mike
 
Upvote 0
What is the value of named range "Dates" ?
- that is your constraint
 
Upvote 0

Forum statistics

Threads
1,215,754
Messages
6,126,681
Members
449,328
Latest member
easperhe29

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