View Single Post
  #4   Report Post  
Old January 28th 09, 03:00 PM posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 7,247
Default find empty cells in a column then append row that empty cell i

Try the following code:

Sub AAA()
Dim FName As Variant
Dim FNum As Integer
Dim LastRow As Long
Dim R As Range
Dim C As Range
Dim S As String
Dim WS As Worksheet
Dim StartRow As Long

FName = Application.GetSaveAsFilename(vbNullString, _
"Text Files (*.txt),*.txt")
If FName = False Then
' user cancelled
Exit Sub
End If
FNum = FreeFile
Open FName For Output Access Write As #FNum
Set WS = ActiveSheet
StartRow = 1
With WS
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Set R = WS.Cells(StartRow, "A")
Do Until R.Value = vbNullString
Set C = R.EntireRow.Cells(1, "A")
S = vbNullString
Do Until C.Value = vbNullString
S = S & C.Text & " "
Set C = C(1, 2)
Loop
S = Trim(S)
Print #FNum, S
Set R = R(2, 1)
Loop
Close #FNum
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 28 Jan 2009 06:46:09 -0800, vbnewbie
wrote:

Thanks for this Bernard it's a good start but I need to display the whole
contents of the row, not just the row numbers, also in a text file rather
than on another sheet.

Hope you can help, or anyone else out there?

Cheers

"Bernard Liengme" wrote:

I am assuming: (1) the column is A, and (2) you want to start at row 1.
This subroutine looks at column A on Sheet2 and on Sheet3 in column A it
lists the row number of every empty cell. The Sheet3 could be copied to a
text file or saved as a TXT file.
best wishes

Sub ListEmpty()
Sheets("Sheet2").Activate
lastcell = Cells(Cells.Rows.Count, "A").End(xlUp).Row
For j = 1 To lastcell
If Cells(j, 1) = "" Then
k = k + 1
Sheets("Sheet3").Cells(k, 1) = j
End If
Next j
End Sub

--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"vbnewbie" wrote in message
...
I am trying to read all empty cells in a column then append the rows that
the
cells are in to a text file using VB6
Microsoft EXCEL 2003