ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   extracting IF (https://www.excelbanter.com/excel-programming/278062-re-extracting-if.html)

Dave Peterson[_3_]

extracting IF
 
Maybe something like:

Option Explicit
Sub testme99()

Dim fWks As Worksheet 'From
Dim tWks As Worksheet 'To
Dim destRow As Long
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim LastCol As Long

LastCol = 255 '= IV really the last column??

Set fWks = Workbooks("book1.xls").Worksheets("sheet1")
Set tWks = Workbooks("book2.xls").Worksheets("sheet1") 'different workbook

With tWks
destRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With

With fWks
FirstRow = 2 'header row in 1???
LastRow = .Cells(.Rows.Count, LastCol).End(xlUp).Row

For iRow = FirstRow To LastRow
If .Cells(iRow, LastCol).Value < "" Then
tWks.Cells(destRow, 1).Resize(1, LastCol).Value _
= .Cells(iRow, 1).Resize(1, LastCol).Value
destRow = destRow + 1
End If
Next iRow
End With

End Sub

martyn wrote:

If need to extract a row of information to another file or
workbook but only if the last column of that row is
populated. Im new to VBA so some sample code would be
excellent!
Many thanks


--

Dave Peterson



All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com