Add row number in Excel

S

swtransaction

I have several spreadsheets that are converted in batch. The row coun
is never the same. I've tried to write some code that did no
reference a specific cell, but I'm having problems.

Here is what I have so far. The problem is the last cell is differen
in every file. I can do this with the row number in the A column, bu
I need it at the end of th spreadsheet.

- go to end row/column
- move one cell to the right
- enter row()
- copy row() from that cell to the top row in that column


ActiveCell.SpecialCells(xlLastCell).Select
Range("R4233").Select
ActiveCell.FormulaR1C1 = "=ROW()"
Range("R4233").Select
Selection.Copy
Range("R4232").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = Fals
 
S

swtransaction

here we go, this works

'add row number at the end of the file
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=ROW()"
Selection.Copy
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
 
D

Dave Peterson

I like to pick out a row/column that is always used when that row/column is
used.

For instance, if Row 1 has headers and column A always has something in it when
the row is used:

dim wks as worksheet
dim LastRow as long
dim LastCol as long

set wks = workbooks(...).worksheets(...)

with wks
lastrow = .cells(.rows.count,"A").end(xlup).row
lastcol = .cells(1,.columns.count).end(xltoleft).column

.range("A1",.cells(lastrow,lastcol)).copy _
destination:=whereeveryouwant

end with
 
G

Guest

sub WriteRowforActiveCell()
cells(1,activecell.column).Value) = _
cells(rows.count,activecell.column).End(xlup)(2).Row
End Sub
 

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