Solved

insert rows and data from above cell

Posted on 2014-12-15
3
88 Views
Last Modified: 2014-12-15
I use the below code provided by Rgonzo to insert cells and the data from above cell including tick boxes which works fine.

However it inserts an entire row and I now need to only insert from A-W and do not want any cells from W >>>> onwards to be impacted.

Can someone provide me with VBA code that will do this please.

Sub Insert()

theRow = InputBox("Enter Row Number where new row is to be inserted ")
Count = InputBox("how many rows ?")

If IsNumeric(Count) And IsNumeric(theRow) And Count > 0 And theRow > 0 And theRow <= Rows.Count Then
    Cells(theRow, 1).Resize(Count, 1).EntireRow.Insert Shift:=xlShiftDown
    a = Cells(CLng(theRow) - 1, 1).Address
    Cells(CLng(theRow) - 1, 1).EntireRow.Copy Destination:=Range(Cells(theRow, 1), Cells(CLng(theRow) + CLng(Count) - 1, 1))
Else
    MsgBox "You didn't enter a valid number!"
End If

End Sub

Thanks
0
Comment
Question by:Jagwarman
  • 2
3 Comments
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40500621
Change

Cells(CLng(theRow) - 1, 1).EntireRow.Copy Destination:=Range(Cells(theRow, 1), Cells(CLng(theRow) + CLng(Count) - 1, 1))

to

Range("A" & CLng(theRow) - 1 & ":V" & CLng(theRow) - 1).Copy Destination:=Range(Cells(theRow, 1), Cells(CLng(theRow) + CLng(Count) - 1, 1))
0
 

Author Comment

by:Jagwarman
ID: 40500671
Thank you Martin
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40500679
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now