LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Looping Help Please

Hello, could someone please have a look at the VBA code below and help
me so that it loops three-times. All the code needs to do is locate the
last cell in the worksheet and format three rows (no data in them).
There is a simple formula copied down in column AT.

It works well for one new row but it cannot find the next "LastCell" in
column A as it is empty.

Any help would be very much appreciated.

Kind regards,

Chris.


Sub Add_New_Record()

' Add New Record
'
'

Dim i As Integer
Dim myR As Long

On Error Resume Next

myR = Worksheets("Position and Incumbent Data").Cells(Rows.Count,
1).End(xlUp).Row

For i = 1 To 3


Application.ScreenUpdating = False

Application.EnableEvents = False

With Sheets("Position and Incumbent Data")

.Cells(.Rows.Count, "A").End(xlUp).Name = "LastCell"

.Cells(.Rows.Count, "AT").End(xlUp).Copy _
Destination:=.Cells(.Rows.Count, "AT") _
.End(xlUp).Offset(1, 0)

End With

Application.EnableEvents = True

Range("LastCell").Select

ActiveCell.Offset(1, 0).Range("A1").Select

ActiveCell.Rows("1:1").EntireRow.Select

Selection.RowHeight = 102

ActiveCell.Range("A1:AT1").Select

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone

With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 8
End With

With Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With

With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With

With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With

With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With

With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With

With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With

With Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With

Sheets("Position and Incumbent Data").Select

Range("LastCell").Offset(2, 0).Select

Next i

Worksheets("Position and Incumbent Data").Cells(myR + 1, 1).Select

End Sub




*** Sent via Developersdex http://www.developersdex.com ***
 
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
About my looping jonathan Excel Programming 3 July 31st 07 02:48 PM
Looping Embalmer Excel Programming 1 January 8th 06 11:51 PM
Not Looping Through teresa Excel Programming 2 June 5th 05 10:33 PM
Looping teresa Excel Programming 2 May 31st 05 01:40 AM
Looping [email protected] Excel Programming 0 October 31st 03 07:47 PM


All times are GMT +1. The time now is 06:45 PM.

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"