Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default PLEASE ANY BODY CAN CORRECT MY MACRO

I have macro (please see below) which is set on a button in a
spreasheet and it works fine. It basically add 6 rows and then merge
cells of those inserted rows from cell "I" to cell "N" and then sort
out number sequense in 2nd coloumn

Sub InsertLines()
Dim LastRow As Long
Dim StartRow As Long
StartRow = Cells(Rows.Count, 2).End(xlUp).Row - 1
Cells(StartRow + 1, 1).Resize(6, 1).EntireRow.Insert
For i = 1 To 6
Cells(StartRow + i, 9).Resize(1, 6).Merge
Next i
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Application.ScreenUpdating = False
With Range(Cells(StartRow, 2), Cells(LastRow, 2))
..DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
End With
Application.ScreenUpdating = True

End Sub

This macro is set on a button but I want to run it exactly as it works
now from sheet module so to do that what I did is that if cell next to
last value cell in coloumn 2 get value then this macro should run and
do exactly the same job what above macro do. but when i tried it it
all gone funny and everything been blocked. i tried to solve this but
nothing coming up. (please see the macro below which i amended to run
it from sheet module) please if any friend can help and tell me the
correct way to do this. Thanks


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRow As Long
Dim StartRow As Long
LLastRow = Cells(Cells.Rows.Count, 2).End(xlUp).Row
If Cells(LLastRow - 1, 1).Offset(0, 1) < "" Then
StartRow = Cells(Rows.Count, 2).End(xlUp).Row - 1
Cells(StartRow + 1, 1).Resize(6, 1).EntireRow.Insert
For i = 1 To 6
Cells(StartRow + i, 9).Resize(1, 6).Merge
Next i
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Application.ScreenUpdating = False
With Range(Cells(StartRow, 2), Cells(LastRow, 2))
..DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
End With
Application.ScreenUpdating = True

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default PLEASE ANY BODY CAN CORRECT MY MACRO

On Mar 20, 12:56*pm, K wrote:
I have macro (please see below) which is set on a button in a
spreasheet and it works fine. It basically add 6 rows and then merge
cells of those inserted rows from cell "I" to cell "N" and then sort
out number sequense in 2nd coloumn

Sub InsertLines()
Dim LastRow As Long
Dim StartRow As Long
StartRow = Cells(Rows.Count, 2).End(xlUp).Row - 1
Cells(StartRow + 1, 1).Resize(6, 1).EntireRow.Insert
For i = 1 To 6
Cells(StartRow + i, 9).Resize(1, 6).Merge
Next i
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Application.ScreenUpdating = False
With Range(Cells(StartRow, 2), Cells(LastRow, 2))
.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
End With
Application.ScreenUpdating = True

End Sub

This macro is set on a button but I want to run it exactly as it works
now from sheet module so to do that what I did is that if cell next to
last value cell in coloumn 2 get value then this macro should run and
do exactly the same job what above macro do. but when i tried it it
all gone funny and everything been blocked. i tried to solve this but
nothing coming up. (please see the macro below which i amended to run
it from sheet module) please if any friend can help and tell me the
correct way to do this. Thanks

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRow As Long
Dim StartRow As Long
LLastRow = Cells(Cells.Rows.Count, 2).End(xlUp).Row
If Cells(LLastRow - 1, 1).Offset(0, 1) < "" Then
StartRow = Cells(Rows.Count, 2).End(xlUp).Row - 1
Cells(StartRow + 1, 1).Resize(6, 1).EntireRow.Insert
For i = 1 To 6
Cells(StartRow + i, 9).Resize(1, 6).Merge
Next i
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Application.ScreenUpdating = False
With Range(Cells(StartRow, 2), Cells(LastRow, 2))
.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
End With
Application.ScreenUpdating = True

End Sub


You missed an "End If" if that helps ... also - are you putting this
in the "Sheet1" section or in the "ThisWorkbook" section? (It should
be "Sheet1").

The macro will run when you doubleclick on a cell or change any value.

Chris
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
Please help correct this macro! :) ninpo1 Excel Programming 2 August 8th 06 08:39 PM
Macro in body of workbook. Can I create XLA? Barb Reinhardt Excel Programming 3 July 5th 06 03:03 PM
Macro help required.Can any body help.........? Thyagaraj Excel Programming 1 June 29th 06 02:31 PM
Adding the message body to a mailto macro Mike Excel Discussion (Misc queries) 0 March 28th 06 03:06 AM
Please correct my macro famdamly Excel Discussion (Misc queries) 5 March 5th 06 08:45 PM


All times are GMT +1. The time now is 08:02 AM.

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"