Solved

insert rows and data from above cell

Posted on 2014-12-15
3
93 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 48

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 48

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

688 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