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: 1
Default stop looping and comments on VBA

I would apprecite if anybody could give any comment on the VBA code
wrote below. It works, but I fell there is a lot need to be improved
Especially the looping for x where i have to stop it at x + 100 becaus
I wouldn't know the value of x. Does anybody have any idea how to sto
x before it reached x + 100.

Thank you very much.

Sub UpdateCheque()

Dim lLastRow As Long
Dim msg1, msgCls
Dim title1, titleCls
Dim default1, defaultCls
Dim strLast, strCls
Dim x As Long
Dim y, z As Long
Dim i As Long
Dim NewRow As Long
Dim ClsChq As Long

With Workbooks("SCSB_Accounts_1Jan04 to 31Dec04"). _
Worksheets("MBB2_Pymt")

lLastRow = .Range("E65536").End(xlUp).Offset(1, 0).Row
y = lLastRow
Do

lLastRow = lLastRow - 1

Loop Until Left(.Cells(lLastRow, "e").value, 2) = "MB"

.Range("f2").value = .Cells(lLastRow, "e").value

msg1 = "What Is The Last Cheque Number, Please Key In The Number I
F2"
title1 = "Last Cheque Number"
default1 = "MBB"

strLast = InputBox(msg1, title1, default1)

msgCls = "What Is The Month You Want To Update"
titleCls = "Closing Month"
defaultCls = "January"

strCls = InputBox(msgCls, titleCls, defaultCls)

x = CLng(Right(strLast, 6))

For x = x To x + 100

For i = Workbooks("PV fo
2004").Worksheets("Data").Range("c65536").End(xlUp ). _
Row To 1 Step -1

If "MBB0" & x = Workbooks("PV for 2004"). _
Worksheets("Data").Cells(i, "c").value Then

Select Case strCls

Case "January"
ClsChq = 1
Case "February"
ClsChq = 2
Case "March"
ClsChq = 3
Case "April"
ClsChq = 4
Case "May"
ClsChq = 5
Case "June"
ClsChq = 6
Case "July"
ClsChq = 7
Case "August"
ClsChq = 8
Case "September"
ClsChq = 9
Case "October"
ClsChq = 10
Case "November"
ClsChq = 11
Case "December"
ClsChq = 12

End Select

If Month(Workbooks("PV fo
2004").Worksheets("Data").Cells(i, "b").value) _
< ClsChq Then Exit For

z = Right(.Cells(lLastRow, "e").value, 6)

NewRow = y + x - z

.Cells(NewRow, "b").value = _
Workbooks("PV for 2004").Worksheets("Data").Cells(i
"b").value
.Cells(NewRow, "b").NumberFormat = "mmm dd"

.Cells(NewRow, "c").value = Workbooks("PV for 2004"). _
Worksheets("Data").Cells(i, "d").value

If Len(Workbooks("PV for 2004"). _
Worksheets("Data").Cells(i, "a").value) = 1 Then
.Cells(NewRow, "d").value = "000" & Workbooks("P
for 2004"). _
Worksheets("Data").Cells(i, "a").value & "/2004"

ElseIf Len(Workbooks("PV for 2004"). _
Worksheets("Data").Cells(i, "a").value) = 2 Then
.Cells(NewRow, "d").value = "00" & Workbooks("P
for 2004"). _
Worksheets("Data").Cells(i, "a").value & "/2004"

ElseIf Len(Workbooks("PV for 2004"). _
Worksheets("Data").Cells(i, "a").value) = 3 Then
.Cells(NewRow, "d").value = "0" & Workbooks("PV fo
2004"). _
Worksheets("Data").Cells(i, "a").value & "/2004"

Else: .Cells(NewRow, "d").value = Workbooks("PV for 2004"
_
.Worksheets("Data").Cells(i, "a").value & "/2004"

End If

.Cells(NewRow, "e").value = Workbooks("PV for 2004"). _
Worksheets("Data").Cells(i, "c").value

.Cells(NewRow, "g").value = Workbooks("PV for 2004"). _
Worksheets("Data").Cells(i, "j").value
.Cells(NewRow, "g").NumberFormat
"#,##0.00_);[Red](#,##0.00)"

.Cells(NewRow, "j").Formula = "=sum(r[0]c[-3]:r[0]c[-1])"
.Cells(NewRow, "j").NumberFormat
"#,##0.00_);[Red](#,##0.00)"

.Cells(NewRow, "k").Formula = "=sum(r[0]c[-5])-sum(r[0]c[-1])"
.Cells(NewRow, "k").NumberFormat
"#,##0.00_);[Red](#,##0.00)"

End If

Next i

Next x

.Cells(y, "a").EntireRow.Delete

End With

End Su

--
Message posted from http://www.ExcelForum.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
excel 2000 how to format the comments font all comments Delquestion Excel Discussion (Misc queries) 1 October 8th 09 02:19 PM
in excel useing comments how do you add clip art to comments? dhouse New Users to Excel 2 July 18th 07 08:14 AM
How do I stop the User names in comments from appearing? Iceman Excel Discussion (Misc queries) 2 March 23rd 06 07:14 PM
How do I stop other circles in other cells to stop selecting? stauff Excel Worksheet Functions 2 October 29th 04 09:02 PM
How do I stop other circles in other boxes to stop selecting? stauff Excel Worksheet Functions 1 October 28th 04 10:27 PM


All times are GMT +1. The time now is 10:31 AM.

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"