Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Code not working after worksheet change.

I have been using the following code for a while. Recently, I deleted the
rows between 2 and 36 and then inserted rows back in so that the sheet looks
exactly the same. However, the code now only works for rows 2 and 36 and
seems to skip over the new rows 4 through 34. If anyone knows why this might
be happening and what I need to do about it, I would really appreciate your
help. Thanks. Code follows:

Sub LastEvent()

Dim fWks As Worksheet
Dim tWks As Worksheet
Dim iRo As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim FirstCol As Long
Dim LastCol As Long
Dim myRng As Range
Dim myCell As Range
Dim myValToCopy As Variant

Set fWks = Worksheets("Tracker")
Set tWks = Worksheets("Stucon Weekly Report")

With fWks
FirstRow = 2
LastRow = 36
FirstCol = .Range("G1").Column
LastCol = .Range("AD1").Column

For iRo = FirstRow To LastRow Step 2
Set myRng = .Range(.Cells(iRo, FirstCol), .Cells(iRo, LastCol))
If myRng.Cells.Count = Application.Count(myRng) _
Or Application.Count(myRng) = 0 Then
Set myCell = Nothing
Else
If IsEmpty(.Cells(iRo, LastCol)) = False Then
Set myCell = .Cells(iRo, LastCol)
Else
If IsEmpty(.Cells(iRo, LastCol - 1)) = False Then
Set myCell = .Cells(iRo, LastCol - 1)
Else
Set myCell = .Cells(iRo, LastCol).End(xlToLeft)
End If
End If
End If
If myCell Is Nothing Then
myValToCopy = ""
Else
myValToCopy = .Cells(1, myCell.Column)
End If
tWks.Cells((iRo / 2) + 3, 6) = myValToCopy
Next iRo
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
worksheet change event not working Jase Excel Discussion (Misc queries) 2 October 27th 08 03:45 PM
change the name of a worksheet/update VBA code Dave F[_2_] Excel Discussion (Misc queries) 1 June 8th 07 09:22 PM
Worksheet change suddenly not working Romanian37[_8_] Excel Programming 3 August 11th 04 11:31 AM
Worksheet change code Frank Kabel Excel Programming 1 July 27th 04 04:58 PM
Enable/Disable Worksheet Change Event code Stuart[_5_] Excel Programming 2 November 3rd 03 07:22 PM


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