Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default this code crashes excel. How come?

Sub copy_1()
Dim SourceRange As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'fill in the Source Sheet and range
Set SourceRange = Sheets("WE 9-8-07").Range("F2:G63")

'Fill in the destination sheet and call the LastRow
'function to find the last row
Set DestSheet = Sheets("DIE STATUS")
Lr = DestSheet.Cells(Rows.count, "A").End(xlUp).Row

'With the information from the LastRow function we can
'create a destination cell and copy/paste the source range
Set DestRange = DestSheet.Range("A" & Lr + 1)
SourceRange.COPY DestRange

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Worksheets("DIE STATUS").Activate
CELLCount = 2
With Worksheets("Die status")
Do While Cells(CELLCount, "A") < ""

Number = Val(Cells(CELLCount, "A"))
Text = Cells(CELLCount, "A")
If InStr(Text, " ") 0 Then
Text = Trim(Mid(Text, InStr(Text, " ")))
.Cells(CELLCount, "A") = Number
.Cells(CELLCount, "C") = Text
CELLCount = CELLCount + 1
End If
Loop
End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default this code crashes excel. How come?

Does it actually crash or merely go into an endless loop, as I would expect
just at a glance at your code. Try changing

CELLCount = CELLCount + 1
End If
Loop


to

End If
CELLCount = CELLCount + 1
Loop

In passing I'd suggest -
Head the module Option Explicit
declare all your variables
don't use variable names like Text & Number
If you are going to qualify .Cells to your sheet with 'With' might as well
qualify all the instances instead of only some. Might not matter in this
case as your 'With' sheet is the Activesheet, otherwise it would give
errors.

Regards,
Peter T

"Nolaughmtr" wrote in message
...
Sub copy_1()
Dim SourceRange As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'fill in the Source Sheet and range
Set SourceRange = Sheets("WE 9-8-07").Range("F2:G63")

'Fill in the destination sheet and call the LastRow
'function to find the last row
Set DestSheet = Sheets("DIE STATUS")
Lr = DestSheet.Cells(Rows.count, "A").End(xlUp).Row

'With the information from the LastRow function we can
'create a destination cell and copy/paste the source range
Set DestRange = DestSheet.Range("A" & Lr + 1)
SourceRange.COPY DestRange

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Worksheets("DIE STATUS").Activate
CELLCount = 2
With Worksheets("Die status")
Do While Cells(CELLCount, "A") < ""

Number = Val(Cells(CELLCount, "A"))
Text = Cells(CELLCount, "A")
If InStr(Text, " ") 0 Then
Text = Trim(Mid(Text, InStr(Text, " ")))
.Cells(CELLCount, "A") = Number
.Cells(CELLCount, "C") = Text
CELLCount = CELLCount + 1
End If
Loop
End With

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default this code crashes excel. How come?

Don't see anything inherent in the code that would cause this. Have you
stepped through it and seen where the crash occurs?

In article ,
Nolaughmtr wrote:

Sub copy_1()
Dim SourceRange As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'fill in the Source Sheet and range
Set SourceRange = Sheets("WE 9-8-07").Range("F2:G63")

'Fill in the destination sheet and call the LastRow
'function to find the last row
Set DestSheet = Sheets("DIE STATUS")
Lr = DestSheet.Cells(Rows.count, "A").End(xlUp).Row

'With the information from the LastRow function we can
'create a destination cell and copy/paste the source range
Set DestRange = DestSheet.Range("A" & Lr + 1)
SourceRange.COPY DestRange

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Worksheets("DIE STATUS").Activate
CELLCount = 2
With Worksheets("Die status")
Do While Cells(CELLCount, "A") < ""

Number = Val(Cells(CELLCount, "A"))
Text = Cells(CELLCount, "A")
If InStr(Text, " ") 0 Then
Text = Trim(Mid(Text, InStr(Text, " ")))
.Cells(CELLCount, "A") = Number
.Cells(CELLCount, "C") = Text
CELLCount = CELLCount + 1
End If
Loop
End With

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default this code crashes excel. How come?

OMG ITS AMAZING!!!!!! Thank you so much!! my first real macro with a loop.
"CHEERS"!!!!

"Peter T" wrote:

Does it actually crash or merely go into an endless loop, as I would expect
just at a glance at your code. Try changing

CELLCount = CELLCount + 1
End If
Loop


to

End If
CELLCount = CELLCount + 1
Loop

In passing I'd suggest -
Head the module Option Explicit
declare all your variables
don't use variable names like Text & Number
If you are going to qualify .Cells to your sheet with 'With' might as well
qualify all the instances instead of only some. Might not matter in this
case as your 'With' sheet is the Activesheet, otherwise it would give
errors.

Regards,
Peter T

"Nolaughmtr" wrote in message
...
Sub copy_1()
Dim SourceRange As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'fill in the Source Sheet and range
Set SourceRange = Sheets("WE 9-8-07").Range("F2:G63")

'Fill in the destination sheet and call the LastRow
'function to find the last row
Set DestSheet = Sheets("DIE STATUS")
Lr = DestSheet.Cells(Rows.count, "A").End(xlUp).Row

'With the information from the LastRow function we can
'create a destination cell and copy/paste the source range
Set DestRange = DestSheet.Range("A" & Lr + 1)
SourceRange.COPY DestRange

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Worksheets("DIE STATUS").Activate
CELLCount = 2
With Worksheets("Die status")
Do While Cells(CELLCount, "A") < ""

Number = Val(Cells(CELLCount, "A"))
Text = Cells(CELLCount, "A")
If InStr(Text, " ") 0 Then
Text = Trim(Mid(Text, InStr(Text, " ")))
.Cells(CELLCount, "A") = Number
.Cells(CELLCount, "C") = Text
CELLCount = CELLCount + 1
End If
Loop
End With

End Sub




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
VBA code crashes Excel 97 - Help please! GB[_2_] Excel Programming 4 April 14th 07 07:15 AM
AddFromString Code - Excel crashes ... Why ? MichDenis Excel Programming 0 January 15th 07 05:49 PM
VBA WinInet Code Crashes Excel [email protected] Excel Programming 0 July 18th 06 09:11 PM
Simple code crashes Excel John[_60_] Excel Programming 1 October 27th 04 05:59 PM
Code in ThisWorkbook crashes Excel Pat Beck Excel Programming 6 August 25th 03 09:07 AM


All times are GMT +1. The time now is 04:02 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"