PC Review


Reply
Thread Tools Rate Thread

Adding Several Rows at a time and Asking for User Input

 
 
Arnold
Guest
Posts: n/a
 
      17th Jan 2007
Hello all,

Have a workbook with 2 sheets--one named "Fields" containing formatted
columns, rows, etc., and another called "Data" containing the data. I
would like the following functionality when adding a new record in Data
(one record consists of 4 rows):

1. Copy the group of 4 formatted rows in the Fields sheet (rows 13
through 16),
2. Activate the Data sheet,
3. Have the user click on a cell in column A above where he or she
wants the 4 rows to be inserted,
4. Insert the 4 rows (adding rows if placed between existing records
so as to not overwrite data),
5. Ask the user for the value of the cells in column A (A-cells in the
4 rows will all be the same value),
6. Ask the user for the value of the cells in column B (all 4 B-cells
will also be the same), and
7. Have Excel fill in the cells with the values.

Also, when inserting the new record (4 rows), a user may happen to
click on any of the rows or cells in column A of the same record, so
the new record would have to be placed below the last used row of the
record.

Hope this makes sense; any help would be greatly appreciated.

Eric

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      18th Jan 2007
This is all untried, untested, but is provided to to give you an idea of
the approach to the solution.


1. Copy the group of 4 formatted rows in the Fields sheet (rows 13
through 16),

Worksheets("Fields).Range("A13:A16).EntireRow.Copy

2. Activate the Data sheet,

Worksheets("Data").Activate


3. Have the user click on a cell in column A above where he or she
wants the 4 rows to be inserted,

LastRow = Cells(Rows.Count,1).End(xlUp).Row
Response = MsgBox("The last row containing data is " & LastRow & ". Do
you want to add the records in the next available
rows?", vbYesNo, "Destination Option"
If Response = vbYes Then
Cells(LastRow + 1,1).Activate
ActiveSheet.Paste
Else
InsOpt = Application.InputBox("Enter a cell in A1
format - example: "A15" - where you want to insert
the records.", "Select Insetion Point", Type:=8)
End If



4. Insert the 4 rows (adding rows if placed between existing records
so as to not overwrite data),

If InsOpt <> Cancel Or InsOPt <> "" Then
Range(Cells(Range(InsOpt).Offset(1,0),1),
Cells(Range(InsOpt).Offset(4,0),1).Select
Selection.EntireRow.Insert
Range(InsOpt).Offset(1,0).Activate
ActiveSheet.Paste
End If


5. Ask the user for the value of the cells in column A (A-cells in the
4 rows will all be the same value),

aVal = InputBox("Enter the value for column A of the inserted records.",
"Col A Values"

6. Ask the user for the value of the cells in column B (all 4 B-cells
will also be the same), and
bVal = InputBox("Enter the value for column B of the inserted records.",
"Col B values"

7. Have Excel fill in the cells with the values.

Range(Cells(Range(InsOpt).Offset(1,0),1),
Cells(Range(InsOpt).Offset(4,0),1) = aVal
Range(Cells(Range(InsOpt).Offset(1,0),2),
Cells(Range(InsOpt).Offset(4,0),2) = bVal



Also, when inserting the new record (4 rows), a user may happen to
click on any of the rows or cells in column A of the same record, so
the new record would have to be placed below the last used row of the
record.

I'm not sure what the last paragraph means.

"Arnold" wrote:

> Hello all,
>
> Have a workbook with 2 sheets--one named "Fields" containing formatted
> columns, rows, etc., and another called "Data" containing the data. I
> would like the following functionality when adding a new record in Data
> (one record consists of 4 rows):
>
> 1. Copy the group of 4 formatted rows in the Fields sheet (rows 13
> through 16),
> 2. Activate the Data sheet,
> 3. Have the user click on a cell in column A above where he or she
> wants the 4 rows to be inserted,
> 4. Insert the 4 rows (adding rows if placed between existing records
> so as to not overwrite data),
> 5. Ask the user for the value of the cells in column A (A-cells in the
> 4 rows will all be the same value),
> 6. Ask the user for the value of the cells in column B (all 4 B-cells
> will also be the same), and
> 7. Have Excel fill in the cells with the values.
>
> Also, when inserting the new record (4 rows), a user may happen to
> click on any of the rows or cells in column A of the same record, so
> the new record would have to be placed below the last used row of the
> record.
>
> Hope this makes sense; any help would be greatly appreciated.
>
> Eric
>
>

 
Reply With Quote
 
Arnold
Guest
Posts: n/a
 
      18th Jan 2007
Lots of Thanks JLGWhiz--will give this a try later on...

JLGWhiz wrote:
> This is all untried, untested, but is provided to to give you an idea of
> the approach to the solution.
>
>
> 1. Copy the group of 4 formatted rows in the Fields sheet (rows 13
> through 16),
>
> Worksheets("Fields).Range("A13:A16).EntireRow.Copy
>
> 2. Activate the Data sheet,
>
> Worksheets("Data").Activate
>
>
> 3. Have the user click on a cell in column A above where he or she
> wants the 4 rows to be inserted,
>
> LastRow = Cells(Rows.Count,1).End(xlUp).Row
> Response = MsgBox("The last row containing data is " & LastRow & ". Do
> you want to add the records in the next available
> rows?", vbYesNo, "Destination Option"
> If Response = vbYes Then
> Cells(LastRow + 1,1).Activate
> ActiveSheet.Paste
> Else
> InsOpt = Application.InputBox("Enter a cell in A1
> format - example: "A15" - where you want to insert
> the records.", "Select Insetion Point", Type:=8)
> End If
>
>
>
> 4. Insert the 4 rows (adding rows if placed between existing records
> so as to not overwrite data),
>
> If InsOpt <> Cancel Or InsOPt <> "" Then
> Range(Cells(Range(InsOpt).Offset(1,0),1),
> Cells(Range(InsOpt).Offset(4,0),1).Select
> Selection.EntireRow.Insert
> Range(InsOpt).Offset(1,0).Activate
> ActiveSheet.Paste
> End If
>
>
> 5. Ask the user for the value of the cells in column A (A-cells in the
> 4 rows will all be the same value),
>
> aVal = InputBox("Enter the value for column A of the inserted records.",
> "Col A Values"
>
> 6. Ask the user for the value of the cells in column B (all 4 B-cells
> will also be the same), and
> bVal = InputBox("Enter the value for column B of the inserted records.",
> "Col B values"
>
> 7. Have Excel fill in the cells with the values.
>
> Range(Cells(Range(InsOpt).Offset(1,0),1),
> Cells(Range(InsOpt).Offset(4,0),1) = aVal
> Range(Cells(Range(InsOpt).Offset(1,0),2),
> Cells(Range(InsOpt).Offset(4,0),2) = bVal
>
>
>
> Also, when inserting the new record (4 rows), a user may happen to
> click on any of the rows or cells in column A of the same record, so
> the new record would have to be placed below the last used row of the
> record.
>
> I'm not sure what the last paragraph means.
>
> "Arnold" wrote:
>
> > Hello all,
> >
> > Have a workbook with 2 sheets--one named "Fields" containing formatted
> > columns, rows, etc., and another called "Data" containing the data. I
> > would like the following functionality when adding a new record in Data
> > (one record consists of 4 rows):
> >
> > 1. Copy the group of 4 formatted rows in the Fields sheet (rows 13
> > through 16),
> > 2. Activate the Data sheet,
> > 3. Have the user click on a cell in column A above where he or she
> > wants the 4 rows to be inserted,
> > 4. Insert the 4 rows (adding rows if placed between existing records
> > so as to not overwrite data),
> > 5. Ask the user for the value of the cells in column A (A-cells in the
> > 4 rows will all be the same value),
> > 6. Ask the user for the value of the cells in column B (all 4 B-cells
> > will also be the same), and
> > 7. Have Excel fill in the cells with the values.
> >
> > Also, when inserting the new record (4 rows), a user may happen to
> > click on any of the rows or cells in column A of the same record, so
> > the new record would have to be placed below the last used row of the
> > record.
> >
> > Hope this makes sense; any help would be greatly appreciated.
> >
> > Eric
> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Certain Rows Based on User Input kmzito@gmail.com Microsoft Excel Programming 1 12th May 2009 01:03 AM
show a number of rows based upon user input P_R Microsoft Excel Misc 1 22nd Apr 2008 08:03 AM
Hiding rows based on user input =?Utf-8?B?UmFuZHk=?= Microsoft Excel Programming 1 7th May 2007 11:50 PM
adding row headings to multiple pages - how do i input the rows? =?Utf-8?B?Y29ubmll?= Microsoft Excel New Users 1 18th May 2006 05:10 PM
Adding calculated time and input times Lesley Microsoft Excel Misc 1 5th Nov 2004 04:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 AM.