Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default any VBA wizz kids out there?

Hi All,

I am sure this has been asked before, but please help as I am going around
in circles! Does anyone have any code / know where I can find code which
will achieve the following?

1) Add a row at the bottom of a table (Table 1), ensuring formatting and
formula are copied down. If the cell above has an inputted data, then then
corresponding cell below needs to be blank.
2) When a user adds a row (by clicking a button say) to Table 1, an
additional row at the bottom of a different table (Table 2) automatically
appears. Table 2 is on another worksheet but within the same excel document.
Again, all the formula, formatting etc needs to be copied down into this new
row in Table 2.

I am sure that there is a simple solution, and sorry if this is a common
question - like I said, going around in circles!

any help would be welcome.

thanks

Paul

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default any VBA wizz kids out there?

There's probably one out here somewhere, but until he or she comes along I'll
try to substitute. Since you didn't give us information about the sheets
(like their names) or the tables (as what columns they occupy and how to tell
what the current last row in each is), I worked up a somewhat generic process
that you will need to change some Const values in to get it to work with your
sheets and table layouts. Note that the sheets can't be protected when you
run this code.

Sub AddTableRows()
'change these Const values to
'describe your two sheets and
'the tables on them.

'define the first
'sheet and table
Const t1SheetName = "Sheet1"
'first/left-most column in the table
Const t1FirstCol = "B"
'last/right-most column in the table
Const t1LastCol = "E"
'column in the table that will
'ALWAYS have some data in it
Const t1KeyCol = "C"
'define the second
'sheet and table
Const t2SheetName = "Sheet2"
'first/left-most column in the table
Const t2FirstCol = "D"
'last/right-most column in the table
Const t2LastCol = "G"
'column in the table that will
'ALWAYS have some data in it
Const t2KeyCol = "G"
'
'variables needed
Dim tWS As Worksheet
Dim tLastRow As Long
Dim tOldLastRow As Range
Dim tNewLastRow As Range
Dim anyNewCell As Range

'work on the first table
Set tWS = ThisWorkbook.Worksheets(t1SheetName)
tLastRow = tWS.Range(t1KeyCol & Rows.Count).End(xlUp).Row
Set tOldLastRow = tWS.Range(t1FirstCol & tLastRow & ":" & _
t1LastCol & tLastRow)
Set tNewLastRow = tWS.Range(t1FirstCol & tLastRow + 1 & ":" & _
t1LastCol & tLastRow + 1)
tOldLastRow.Copy

tNewLastRow.PasteSpecial Paste:=xlPasteFormats, _
Operation:=xlNone, SkipBlanks:=False, _
Transpose:=False
tNewLastRow.PasteSpecial Paste:=xlPasteFormulas, _
Operation:=xlNone, SkipBlanks:=False, _
Transpose:=False
Application.CutCopyMode = False
For Each anyNewCell In tNewLastRow
If anyNewCell.HasFormula = False Then
anyNewCell.ClearContents
End If
Next

'process the 2nd table
Set tWS = ThisWorkbook.Worksheets(t2SheetName)
tLastRow = tWS.Range(t2KeyCol & Rows.Count).End(xlUp).Row
Set tOldLastRow = tWS.Range(t2FirstCol & tLastRow & ":" & _
t2LastCol & tLastRow)
Set tNewLastRow = tWS.Range(t2FirstCol & tLastRow + 1 & ":" & _
t2LastCol & tLastRow + 1)
tOldLastRow.Copy

tNewLastRow.PasteSpecial Paste:=xlPasteFormats, _
Operation:=xlNone, SkipBlanks:=False, _
Transpose:=False
tNewLastRow.PasteSpecial Paste:=xlPasteFormulas, _
Operation:=xlNone, SkipBlanks:=False, _
Transpose:=False
Application.CutCopyMode = False
For Each anyNewCell In tNewLastRow
If anyNewCell.HasFormula = False Then
anyNewCell.ClearContents
End If
Next

'housekeeping
Set tNewLastRow = Nothing
Set tOldLastRow = Nothing
Set tWS = Nothing

End Sub


"Paul" wrote:

Hi All,

I am sure this has been asked before, but please help as I am going around
in circles! Does anyone have any code / know where I can find code which
will achieve the following?

1) Add a row at the bottom of a table (Table 1), ensuring formatting and
formula are copied down. If the cell above has an inputted data, then then
corresponding cell below needs to be blank.
2) When a user adds a row (by clicking a button say) to Table 1, an
additional row at the bottom of a different table (Table 2) automatically
appears. Table 2 is on another worksheet but within the same excel document.
Again, all the formula, formatting etc needs to be copied down into this new
row in Table 2.

I am sure that there is a simple solution, and sorry if this is a common
question - like I said, going around in circles!

any help would be welcome.

thanks

Paul

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
One for the chart wiz kids [email protected] Excel Discussion (Misc queries) 2 April 29th 07 07:50 PM
need a roster that 3 kids can work to day by day? Mr Derek Green Excel Worksheet Functions 2 October 10th 05 07:14 PM
something having kids altogather from different countries Amita Excel Discussion (Misc queries) 0 September 20th 05 04:23 AM
How can I compute a kids age based on his birthdate Coach T Excel Worksheet Functions 5 July 4th 05 04:01 PM
Does anyone know a good template for kids chores? jlandreth Excel Discussion (Misc queries) 0 May 10th 05 10:01 PM


All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"