Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Improving this code

Hi guys, I wonder if someone may help me to improve this code, basically read
the worksheet "Personal Budget" until it find the word Final, the are some
empty lines that is why I ask if the cell is not empty, if is not empty I
copy the information sequentially to the worksheet where I am running the
Command Button, this code works but I was wondering if there is a way to
improved, maybe there is a way to do it without the do while cycle.

Thanks

Private Sub CommandButton1_Click()
Dim Row As Integer, row2 As Integer, Count As Integer
Row = 1
row2 = 5

Do While Worksheets("Personal Budget").Cells(row2, 2) < "Final"
If Worksheets("Personal Budget").Cells(row2, 2) < "" Then
Cells(Row, 1) = Worksheets("Personal Budget").Cells(row2, 2).Value
Row = Row + 1
End If
row2 = row2 + 1
Loop
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Improving this code

One way:

Sub NoWhile()
Dim FinalCell As Range
With Worksheets("Personal Budget")
Set FinalCell = .Columns(2).Find("Final")
If Not FinalCell Is Nothing Then
.Range(.Cells(5, 2), FinalCell.Offset(-1)) _
.SpecialCells(xlCellTypeConstants).Copy
Cells(1, 2).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End If
End With
End Sub


--
Jim
"Orlando" wrote in message
...
Hi guys, I wonder if someone may help me to improve this code, basically
read
the worksheet "Personal Budget" until it find the word Final, the are some
empty lines that is why I ask if the cell is not empty, if is not empty I
copy the information sequentially to the worksheet where I am running the
Command Button, this code works but I was wondering if there is a way to
improved, maybe there is a way to do it without the do while cycle.

Thanks

Private Sub CommandButton1_Click()
Dim Row As Integer, row2 As Integer, Count As Integer
Row = 1
row2 = 5

Do While Worksheets("Personal Budget").Cells(row2, 2) < "Final"
If Worksheets("Personal Budget").Cells(row2, 2) < "" Then
Cells(Row, 1) = Worksheets("Personal Budget").Cells(row2, 2).Value
Row = Row + 1
End If
row2 = row2 + 1
Loop
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Improving this code

Your code is pretty efficient. Here is another way of doing the same thing

RowCount = 1
with Worksheets("Personal Budget")
LastRow = .cells(rows.count,"B").end(xlup).row
Set ColBRange = range(.cells(1,"B"),.cells(LastRow,"B"))

set c = ColBRange.Find(what:="Final",lookin:=xlvalues)
if not c is nothing then

Set ColBRange = range(.cells(1,"B"),.cells(c.Row,"B"))
for each cell in ColBRange
if not isempty(cell) then
.Cells(RowCount, 1).value = cell
RowCount = RowCount + 1
end if
next cell
end if


"Orlando" wrote:

Hi guys, I wonder if someone may help me to improve this code, basically read
the worksheet "Personal Budget" until it find the word Final, the are some
empty lines that is why I ask if the cell is not empty, if is not empty I
copy the information sequentially to the worksheet where I am running the
Command Button, this code works but I was wondering if there is a way to
improved, maybe there is a way to do it without the do while cycle.

Thanks

Private Sub CommandButton1_Click()
Dim Row As Integer, row2 As Integer, Count As Integer
Row = 1
row2 = 5

Do While Worksheets("Personal Budget").Cells(row2, 2) < "Final"
If Worksheets("Personal Budget").Cells(row2, 2) < "" Then
Cells(Row, 1) = Worksheets("Personal Budget").Cells(row2, 2).Value
Row = Row + 1
End If
row2 = row2 + 1
Loop
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
Improving formula Brad Excel Worksheet Functions 1 April 6th 06 06:02 PM
Improving use of Worksheets TKeune Excel Worksheet Functions 2 February 11th 06 10:59 AM
advice on improving code PC[_3_] Excel Programming 2 April 6th 04 11:37 AM
Trying to improving existing code (portion of) Cameron[_6_] Excel Programming 5 April 4th 04 12:29 AM
Improving code.....For Next Mat Excel Programming 3 October 30th 03 06:01 AM


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

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"