LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default If Then in VBA, check cell, enter data to other cell

It tested you code:

Sub copy_to_another_workbook()
Dim sourceRange As Range
Dim destrange As Range
Dim destWB As Workbook
Dim Lr As Long

Application.ScreenUpdating = False
' If bIsBookOpen("test.xls") Then
' Set destWB = Workbooks("test.xls")
' Else
' Set destWB = Workbooks.Open("P:\COBdata\test.xls")
' End If
' Lr = LastRow(destWB.Worksheets("Sheet1")) + 1

' Set sourceRange = ThisWorkbook.Worksheets( _
' "COB_Cover_Sheet").Range("A1:C10")

With ThisWorkbook.Worksheets("Sheet1")
Set sourceRange = .Range("B19:V" & _
.Range("A" & Rows.Count).End(xlUp).Row)
End With
For Each cell In sourceRange.Columns(1).Cells
If cell.Value = 0 Then
Set sourceRange = sourceRange.Resize(cell.Row - 19)
Exit For
End If
Next
sourceRange.Select
Exit Sub
Set destrange = destWB.Worksheets("Sheet1").Range("A" & Lr)
sourceRange.Copy
destrange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub


and it worked perfectly for me - especially for my contribution. If there
is a problem, it is probably that you don't have data extending down in
column A - but that was you code.

--
Regards,
Tom Ogilvy

"Win" wrote in message
...
Tom,
Thank you for the reply, I tried the code and it stops at the line marked
with **'s., Might you have any ideas

Thank You Again

Win

for each cell in sourceRange.columns(1).cells
if cell.Value = 0 then
***** set sourceRange = sourcerange.Resize(cell.row - 19) ******
exit for
end if
Next

Set destrange = destWB.Worksheets("Sheet1").Range("A" & Lr)
sourceRange.Copy
destrange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub




 
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
Enter data and press enter to move to specific cell Programing problem[_2_] Excel Programming 2 January 10th 07 03:35 AM
Auto enter date when data in enter in another cell Brian Excel Worksheet Functions 5 December 7th 06 06:44 PM
Force user to enter data in cell before moving to next cell Fusionmags New Users to Excel 3 November 19th 06 11:49 PM
enter data in cell but cannot save until click off cell in excel T70McCains Excel Discussion (Misc queries) 1 November 18th 05 05:06 PM
how do I do a check on the data enter in the cell? Cell check Excel Programming 1 August 31st 05 11:22 AM


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