Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Script is bogging down and will not end

can anyone take a look at this script and show me if there is a way to
make it run more efficient? when i run this script it boggs and
actually never ends. i end up having to break the code to stop it.

Sub addtext_main()

Dim strCellAbove As String
Dim strCurrentCell As String
Dim s As String
Dim cell As Range

nlastrow = ActiveSheet.UsedRange.Rows.Count + ActiveSheet.UsedRange.Row
- 1
myrow = Selection.Row
howmany = nlastrow - myrow

Set cell2 = Range(Selection, Selection.Offset(howmany, 0))
cell2.Select

For Each cell In Selection
If Asc(Left(cell.Text, 1)) = 97 And Asc(Left(cell.Text, 1)) <=
122 Then
cell.Offset(-1, 0).Value = cell.Offset(-1, 0).Value & " " &
cell.Value
ActiveSheet.Rows(cell.Row).Delete
End If

Next

End Sub

God bless
jsd219

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Script is bogging down and will not end

Maybe something like this:

Sub addtext_main()
Dim nlastrow as Long
Dim myRow as Long
Dim cell As Range
Dim col as Long

col = Activecell.Column

nlastrow = ActiveSheet.UsedRange.Rows.Count + _
ActiveSheet.UsedRange.Row - 1
myrow = Selection.Row
howmany = nlastrow - myrow

for i = nlastrow to myrow step -1

set cell = cells(i,col)
If Asc(Left(cell.Text, 1)) = 97 And _
Asc(Left(cell.Text, 1)) <= 122 Then
cell.Offset(-1, 0).Value = cell.Offset(-1, 0).Value _
& " " & cell.Value
ActiveSheet.Rows(i).Delete
End If

Next

End Sub

--
Regards,
Tom Ogilvy




"jsd219" wrote:

can anyone take a look at this script and show me if there is a way to
make it run more efficient? when i run this script it boggs and
actually never ends. i end up having to break the code to stop it.

Sub addtext_main()

Dim strCellAbove As String
Dim strCurrentCell As String
Dim s As String
Dim cell As Range

nlastrow = ActiveSheet.UsedRange.Rows.Count + ActiveSheet.UsedRange.Row
- 1
myrow = Selection.Row
howmany = nlastrow - myrow

Set cell2 = Range(Selection, Selection.Offset(howmany, 0))
cell2.Select

For Each cell In Selection
If Asc(Left(cell.Text, 1)) = 97 And Asc(Left(cell.Text, 1)) <=
122 Then
cell.Offset(-1, 0).Value = cell.Offset(-1, 0).Value & " " &
cell.Value
ActiveSheet.Rows(cell.Row).Delete
End If

Next

End Sub

God bless
jsd219


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Script is bogging down and will not end

Thank you guys so much, :-)

Running much faster now

God bless
jsd219


Tom Ogilvy wrote:
Maybe something like this:

Sub addtext_main()
Dim nlastrow as Long
Dim myRow as Long
Dim cell As Range
Dim col as Long

col = Activecell.Column

nlastrow = ActiveSheet.UsedRange.Rows.Count + _
ActiveSheet.UsedRange.Row - 1
myrow = Selection.Row
howmany = nlastrow - myrow

for i = nlastrow to myrow step -1

set cell = cells(i,col)
If Asc(Left(cell.Text, 1)) = 97 And _
Asc(Left(cell.Text, 1)) <= 122 Then
cell.Offset(-1, 0).Value = cell.Offset(-1, 0).Value _
& " " & cell.Value
ActiveSheet.Rows(i).Delete
End If

Next

End Sub

--
Regards,
Tom Ogilvy




"jsd219" wrote:

can anyone take a look at this script and show me if there is a way to
make it run more efficient? when i run this script it boggs and
actually never ends. i end up having to break the code to stop it.

Sub addtext_main()

Dim strCellAbove As String
Dim strCurrentCell As String
Dim s As String
Dim cell As Range

nlastrow = ActiveSheet.UsedRange.Rows.Count + ActiveSheet.UsedRange.Row
- 1
myrow = Selection.Row
howmany = nlastrow - myrow

Set cell2 = Range(Selection, Selection.Offset(howmany, 0))
cell2.Select

For Each cell In Selection
If Asc(Left(cell.Text, 1)) = 97 And Asc(Left(cell.Text, 1)) <=
122 Then
cell.Offset(-1, 0).Value = cell.Offset(-1, 0).Value & " " &
cell.Value
ActiveSheet.Rows(cell.Row).Delete
End If

Next

End Sub

God bless
jsd219



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
help with vba script lariveesl New Users to Excel 5 June 6th 09 08:53 AM
Need Help with Script DustinS Excel Programming 1 September 5th 05 02:53 PM
VB Script Steph[_3_] Excel Programming 3 June 1st 05 04:49 PM
Excel 2000/XP script to Excel97 script hat Excel Programming 3 March 2nd 04 03:56 PM
what is a vb script george Excel Programming 1 July 16th 03 09:56 AM


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

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"