?
Solved

insert rows and data from above cell

Posted on 2014-12-15
3
Medium Priority
?
96 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

752 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