Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2004, 08:08 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert Row where User Specifies

Hey there,

I have a spreadsheet with 3 sheets. I need some help of how to insert a new blank row where a user may specify he/she wants it i.e where this new row goes no one knows!!!!!


The problem gets trickier as the three sheets are completely identical, just holding different bits of information on price, quantity and revenue. So if a new row goes into the price sheet - a similar one must go into the other two spreadsheets.

I managed to get the following code which uses an input box - But i would like to use an REFEDIT Control (which i have little experience in using).

TheRow = InputBox("Enter the line below where you want the blank row to be inserted")
If IsNumeric(TheRow) Then
    For n = 1 To 3
        Sheets(n).Rows(CInt(TheRow)).EntireRow.Insert
    Next n
Else
    MsgBox "You must enter a number"
End If

Also I require an extension to the code - whereby the user can specify what he wants in that new i.e what he wants to put in there and this need to be transferred to all the sheets.


Any direction/help much appreciated!!!!!


 
Old April 13th, 2004, 04:59 PM
Authorized User
 
Join Date: Feb 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why not have the user pick on screen for the row? Make your code like this:

Sub InsertRow()
    Dim TheRow As Range
    On Error GoTo InsertRow_ErrorHandler:

    'This gets the user to pick
    Set TheRow = Application.InputBox(Prompt:="Enter the line below where you want the blank row to be inserted", Type:=8)
    If Not TheRow Is Nothing Then
        'Allow only one row
        For n = 1 To 3
            Sheets(n).Rows(TheRow.Row).EntireRow.Insert
        Next n
    Else
        MsgBox "You must enter a number"
    End If

InsertRow_ErrorHandler:
    Select Case Err.Number
        Case 0
        Case 424
            Err.Clear
        Case Else
            MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure InsertRow of Module Module1"
            Err.Clear
    End Select
    'Clean Up
    Set TheRow = Nothing
End Sub


Dave





Similar Threads
Thread Thread Starter Forum Replies Last Post
insert row into table stealthdevil Access VBA 11 June 16th, 2007 08:32 AM
How to insert row no automatically Jane SQL Server 2000 1 January 13th, 2006 12:20 PM
Dynamically Insert Row fs22 Javascript How-To 1 July 9th, 2005 04:47 AM
insert row to database heathonbass C# 2 December 19th, 2004 01:02 AM
stringgrid-insert row nas Visual C++ 0 December 10th, 2004 01:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.