[Excel] Loop and not empty cells

M

Marc

Hi,

I want to print some cells (in a output txt file) from my excel sheet using
a macro.

For example, I know that my data start at row 6 but I don't know which is
the last not empty row.
Then, I want to print to my output file the cell of the current row and the
A column and that of the C column if its not empty (Print #OutNum,
Excel.Range(currentRow ??))

Thx for your help
 
I

Iolaire McFadden

This is how I grab one cell at a time from a work sheet.
Will it help you?
<code>
Public cell_value
Sub loop_through_markets()
Sheets("sheet_one").Select
myrow = 2 ' start loop at row 2 - change as needed
myCol = 1 ' start loop at column 1 - change as needed
Set cell_value = Worksheets("sheet_one").Cells(myrow,
myCol)
Do While cell_value <> ""

''' add script here

myrow = myrow + 1
Set cell_value = Worksheets("sheet_one").Cells(myrow,
myCol)
Loop
End Sub
</code>
 
M

Marc

Thanks for your post , but I write somethimg like that :

'#CURRENT CODE

Dim firstRow As Integer
Dim lastRow As Integer
Dim i As Integer

firstRow = pCells.Range("A6").Row
lastRow = Cells([A65536].End(xlUp).Row, 1).Row

For i = firstRow To lastRow
Print #fOutputNum, Cells(i, 1).value & vbTab & Cells(i, 4).value
Next

'# END OF CODE

I added a test on Cell(i,4).value > "" and know its working well


Thx

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top