Insert row numbers

  • Thread starter Thread starter sjharri
  • Start date Start date
S

sjharri

Hi,

I need to insert row numbers to a csv file that is generated from a
spreadsheet of data. Thought I could user NumberRows() but not sure if
this is correct.

Could someone tell me the best way to insert row numbers for each row
of data. The amount of data varies each time the csv file is generated.

Thanks
Steve
 
This task is easier in the worksheet than VBA. Pick an un-used column and
enter:

=ROW() and copy down
 
I'd insert a new row A.

Then pick out a column that always has data:

Option Explicit
Sub testme02()
Dim wks As Worksheet
Dim LastRow As Long
Set wks = ActiveSheet
With wks
.Range("a1").EntireColumn.Insert
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
With .Range("a1:A" & LastRow)
.Formula = "=row()"
.Value = .Value
End With
End With
End Sub
 
I'd insert a new COLUMN A.

Dave said:
I'd insert a new row A.

Then pick out a column that always has data:

Option Explicit
Sub testme02()
Dim wks As Worksheet
Dim LastRow As Long
Set wks = ActiveSheet
With wks
.Range("a1").EntireColumn.Insert
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
With .Range("a1:A" & LastRow)
.Formula = "=row()"
.Value = .Value
End With
End With
End Sub
 
I am getting the message invalid or unqualified reference for the .rows
in the following line.

LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

Any ideas?

Thanks
 

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

Back
Top