ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Script is bogging down and will not end (https://www.excelbanter.com/excel-programming/376270-script-bogging-down-will-not-end.html)

jsd219

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


Jim Cone

Script is bogging down and will not end
 
Sub addtext_main()
Dim cell As Range
Dim Allcells As Range
Set Allcells = Selection

For Each cell In Allcells.Columns(1).Cells
If Len(cell.Text) Then
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
cell.EntireRow.Delete
End If
End If
Next
End Sub

--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"jsd219"
wrote in message
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


Jim Thomlinson

Script is bogging down and will not end
 
There is a bunch of stuff that could be done to clean it up but what exactly
is it supposed to do???
--
HTH...

Jim Thomlinson


"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




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com