Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Frick
 
Posts: n/a
Default Macro to add more lines

I need to create a macro, attached to a button that will go to the last line
in col B and copy that line down one row so that all the formulas in the
last line form col's B through G are copied down to the next row.

I have created the button but I don't know how to create the macro.

Thank you for any help.


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Mark
 
Posts: n/a
Default Macro to add more lines

This will do the trick

Private Sub CommandButton1_Click()

Dim CurRow As Integer
Dim ColLtr(5) As String
Dim CurCol As Integer

ColLtr(0) = "B"
ColLtr(1) = "C"
ColLtr(2) = "D"
ColLtr(3) = "E"
ColLtr(4) = "F"
ColLtr(5) = "G"

Application.ScreenUpdating = False
For CurCol = 0 To UBound(ColLtr)

CurRow = 0
Debug.Print " The currently selected column is " & _
ColLtr(CurCol)
CurRow = CurRow + 1
Range(ColLtr(CurCol) & CurRow).Select
Do Until Selection = ""
Range(ColLtr(CurCol) & CurRow).Select
CurRow = CurRow + 1
Loop
Range(ColLtr(CurCol) & CurRow).Offset(-1, 0) = _
Range(ColLtr(CurCol) & CurRow).Offset(-2, 0)

Next CurCol
Application.ScreenUpdating = True

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Frick
 
Posts: n/a
Default Macro to add more lines

Mark,

Thanks for the reply. I added the script and attached to Command Button 1.
When I clicked on the button the script executed but stopped at;

Range(ColLtr(CurCol) & CurRow).Offset(-1, 0) = _
Range(ColLtr(CurCol) & CurRow).Offset(-2, 0)

I am not sure why that happened. Presently the worksheet I created has data
in Col B from row 12 through 27. When I click on the button it should go to
row 27 and copy a new row to row 28, copying col's B through G.

Can you further assist.

Frick

"Mark" wrote in message
oups.com...
This will do the trick

Private Sub CommandButton1_Click()

Dim CurRow As Integer
Dim ColLtr(5) As String
Dim CurCol As Integer

ColLtr(0) = "B"
ColLtr(1) = "C"
ColLtr(2) = "D"
ColLtr(3) = "E"
ColLtr(4) = "F"
ColLtr(5) = "G"

Application.ScreenUpdating = False
For CurCol = 0 To UBound(ColLtr)

CurRow = 0
Debug.Print " The currently selected column is " & _
ColLtr(CurCol)
CurRow = CurRow + 1
Range(ColLtr(CurCol) & CurRow).Select
Do Until Selection = ""
Range(ColLtr(CurCol) & CurRow).Select
CurRow = CurRow + 1
Loop
Range(ColLtr(CurCol) & CurRow).Offset(-1, 0) = _
Range(ColLtr(CurCol) & CurRow).Offset(-2, 0)

Next CurCol
Application.ScreenUpdating = True

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Trevor Shuttleworth
 
Posts: n/a
Default Macro to add more lines

One way:

Private Sub CommandButton1_Click()
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = Range("B65536").End(xlUp).Row
Range("B" & LastRow & ":G" & LastRow).Copy _
Range("B" & LastRow + 1)
Application.ScreenUpdating = True
End Sub

This assumes all the columns have data down to the same row.

Regards

Trevor


"Frick" wrote in message
...
I need to create a macro, attached to a button that will go to the last
line in col B and copy that line down one row so that all the formulas in
the last line form col's B through G are copied down to the next row.

I have created the button but I don't know how to create the macro.

Thank you for any help.



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
Deleting unused lines between used lines? Stevel Setting up and Configuration of Excel 1 November 25th 05 12:58 AM
Can T Get Macro To Run! Nipper New Users to Excel 2 November 4th 05 04:48 AM
Macro to insert blank lines Terry Pinnell Excel Discussion (Misc queries) 6 October 21st 05 11:21 PM
Help: I need a macro to add words every 3 lines Mirandolle Excel Discussion (Misc queries) 11 August 7th 05 05:03 PM
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM


All times are GMT +1. The time now is 12:57 PM.

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

About Us

"It's about Microsoft Excel"