Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Autofill - Autonumbering

I am trying to place line numbering down one column of my
data. I have tried cheating and using autofill, but when
I enter a variable it doens't seem to work. Here is what
I have got right now;

For h = 15 To Cells(Rows.Count, "B").End(xlUp).Row
If Range("B" & h).Value < "" Then
Range("A15:A16").Select
Selection.AutoFill Destination:=Range("A15"
& ":A" & h), Type:=xlFillDefault
End If
Next h

The autofill is cheating and I would like to know if
their is a better way of doing it.

Thanks in advance,
Greg
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Autofill - Autonumbering

Here is one approach:
Sub Tester2()
Dim rng As Range
Set rng = Cells(Rows.Count, "B").End(xlUp)
Range("A15").Value = 1
Range("A15").AutoFill Destination:= _
Range(Range("A15"), rng.Offset(0, -1)), _
Type:=xlFillSeries
End Sub

if you are trying to number just in cells where column B has values.

Sub Tester3()
Dim rng As Range
Dim i As Long, cell As Range
Set rng = Cells(Rows.Count, "B").End(xlUp)
Set rng = Range(Range("B15"), rng)
i = 1
For Each cell In rng
If cell < "" Then
cell.Offset(0, -1).Value = i
i = i + 1
End If
Next
End Sub

--
Regards,
Tom Ogilvy

"Greg" wrote in message
...
I am trying to place line numbering down one column of my
data. I have tried cheating and using autofill, but when
I enter a variable it doens't seem to work. Here is what
I have got right now;

For h = 15 To Cells(Rows.Count, "B").End(xlUp).Row
If Range("B" & h).Value < "" Then
Range("A15:A16").Select
Selection.AutoFill Destination:=Range("A15"
& ":A" & h), Type:=xlFillDefault
End If
Next h

The autofill is cheating and I would like to know if
their is a better way of doing it.

Thanks in advance,
Greg



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Autofill - Autonumbering

Autofill is hardly cheating. One way:

With Range("B" & Rows.Count).End(xlUp)
If .Row 16 Then
Range("A15:A16").AutoFill _
Destination:=Range("A15:A" & .Row), _
Type:=xlFillDefault
End If
End With


In article ,
"Greg" wrote:

I am trying to place line numbering down one column of my
data. I have tried cheating and using autofill, but when
I enter a variable it doens't seem to work. Here is what
I have got right now;

For h = 15 To Cells(Rows.Count, "B").End(xlUp).Row
If Range("B" & h).Value < "" Then
Range("A15:A16").Select
Selection.AutoFill Destination:=Range("A15"
& ":A" & h), Type:=xlFillDefault
End If
Next h

The autofill is cheating and I would like to know if
their is a better way of doing it.

Thanks in advance,
Greg

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Autofill - Autonumbering

Doesn't seem to do anything if A15 and A16 are blank.

this worked:
Sub AAA1()
With Range("B" & Rows.Count).End(xlUp)
If .Row 16 Then
Range("A15:A16") = Evaluate("{1;2}")
Range("A15:A16").AutoFill _
Destination:=Range("A15:A" & .Row), _
Type:=xlFillDefault
End If
End With
End Sub

Were you assuming they were filled or does it work the way written on the
MAC?

--
Regards,
Tom Ogilvy



"John McGimpsey" wrote in message
...
Autofill is hardly cheating. One way:

With Range("B" & Rows.Count).End(xlUp)
If .Row 16 Then
Range("A15:A16").AutoFill _
Destination:=Range("A15:A" & .Row), _
Type:=xlFillDefault
End If
End With


In article ,
"Greg" wrote:

I am trying to place line numbering down one column of my
data. I have tried cheating and using autofill, but when
I enter a variable it doens't seem to work. Here is what
I have got right now;

For h = 15 To Cells(Rows.Count, "B").End(xlUp).Row
If Range("B" & h).Value < "" Then
Range("A15:A16").Select
Selection.AutoFill Destination:=Range("A15"
& ":A" & h), Type:=xlFillDefault
End If
Next h

The autofill is cheating and I would like to know if
their is a better way of doing it.

Thanks in advance,
Greg



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Autofill - Autonumbering

I was assuming (from the OP's original code) that they were filled.

In article ,
"Tom Ogilvy" wrote:

Were you assuming they were filled or does it work the way written on the
MAC?


--
Microsoft MVP-Macintosh
http://www.mcgimpsey.com/macoffice
http://www.mcgimpsey.com/excel


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autonumbering hmk311 Excel Worksheet Functions 5 October 27th 07 01:07 AM
Autonumbering in Excel ryadav Excel Discussion (Misc queries) 1 July 27th 06 07:17 PM
autonumbering Lino Excel Worksheet Functions 2 May 30th 05 02:33 AM
Better autonumbering formula? Dan in NY Excel Worksheet Functions 7 March 22nd 05 10:42 PM
Autonumbering Greg Excel Programming 2 February 4th 04 01:34 PM


All times are GMT +1. The time now is 11:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"