W
Win
Hello all,
I am very new to Excel VBA stuff so I hope I explain this right. I have a
sheet that data pulled into from another worksheet. The data is pulled via
(=Sheet2!B19) being in the cell on sheet1. The number of rows below B19 can
vary.
After the data is worked, I want to be able to copy the results to a
different workbook. I have the code working to copy the rows but the problem
I have is that if I tell the code to select the last row with data in column
B it does not stop at the last row of new data since the function in the
cells creates a "0" (zero) in the cells.
I would like to get the code to check column B from B19 down, When it finds
a "0" (zero) think of that as the last row to copy. See below for the code I
am using now.
Sample of data...
A1 .... B1..... C1 ...> to V1
row19 Data data >>>>>
row20 data data >>>>
row21 0
& 0n 0
I need to come up with a way to have VBA find the row that = 0 or the other
way I thought of but can not code is to have VBA check for a zero in column B
and if find one enter a X in the cell to the left (A21) nin above sample.
my code as of now ...
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
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
I am very new to Excel VBA stuff so I hope I explain this right. I have a
sheet that data pulled into from another worksheet. The data is pulled via
(=Sheet2!B19) being in the cell on sheet1. The number of rows below B19 can
vary.
After the data is worked, I want to be able to copy the results to a
different workbook. I have the code working to copy the rows but the problem
I have is that if I tell the code to select the last row with data in column
B it does not stop at the last row of new data since the function in the
cells creates a "0" (zero) in the cells.
I would like to get the code to check column B from B19 down, When it finds
a "0" (zero) think of that as the last row to copy. See below for the code I
am using now.
Sample of data...
A1 .... B1..... C1 ...> to V1
row19 Data data >>>>>
row20 data data >>>>
row21 0
& 0n 0
I need to come up with a way to have VBA find the row that = 0 or the other
way I thought of but can not code is to have VBA check for a zero in column B
and if find one enter a X in the cell to the left (A21) nin above sample.
my code as of now ...
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
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