#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Do while

Hi,

I have the following script in vb:
Dim LNID as range
Dim i as range
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set LNID = Workbooks("FILE1").Worksheets("CONSTANTS").Range(" I11")

Do
LNID = LNID + 1
Set i = Range("B2:B" & LNID)
LNID.Copy i
Loop Until LNID = LastRow

LNID is a constant (= 0) What I want is to add a line number to Column B. So
in Cell B2 there should be a 1 in there and in cell B3 a 3 should be copied.
Now all the cells have the same number (there are 200 lines in column C) so
the number 200 is copied to all cells in column B. it should be 1,2,3,4 etc.
Can anyone help with this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Do while

Frank,

I'm not sure I understand what you are doing with the variable LNID but if
you simply want to start in B2 and number down for the length of column C
then try this:-

Sub strata()
Dim LNID As Range
lastrowcolc = Range("c65536").End(xlUp).Row
Set LNID = Workbooks("book1").Worksheets("CONSTANTS").Range(" I11")
Set myrange = Range("b2:B" & lastrowcolc)
For Each c In myrange
c.Value = LNID
LNID = LNID + 1
Next
End Sub

Mike



"Frank" wrote:

Hi,

I have the following script in vb:
Dim LNID as range
Dim i as range
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set LNID = Workbooks("FILE1").Worksheets("CONSTANTS").Range(" I11")

Do
LNID = LNID + 1
Set i = Range("B2:B" & LNID)
LNID.Copy i
Loop Until LNID = LastRow

LNID is a constant (= 0) What I want is to add a line number to Column B. So
in Cell B2 there should be a 1 in there and in cell B3 a 3 should be copied.
Now all the cells have the same number (there are 200 lines in column C) so
the number 200 is copied to all cells in column B. it should be 1,2,3,4 etc.
Can anyone help with this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Do while

Frank,
You have declared LNID as a range, so this makes no sense, in fact will give
a type Mismatch error:
LNID = LNID + 1

Also, this statement is clearly wrong: "LNID is a constant (= 0)".
After that, I cannot understand your stated requirements, but possibly look
in the help for AutoFill.

NickHK

"Frank" wrote in message
...
Hi,

I have the following script in vb:
Dim LNID as range
Dim i as range
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set LNID = Workbooks("FILE1").Worksheets("CONSTANTS").Range(" I11")

Do
LNID = LNID + 1
Set i = Range("B2:B" & LNID)
LNID.Copy i
Loop Until LNID = LastRow

LNID is a constant (= 0) What I want is to add a line number to Column B.

So
in Cell B2 there should be a 1 in there and in cell B3 a 3 should be

copied.
Now all the cells have the same number (there are 200 lines in column C)

so
the number 200 is copied to all cells in column B. it should be 1,2,3,4

etc.
Can anyone help with this?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Do while

Dim LNID As Range
Dim i As Range
Dim lastrow As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set LNID = Workbooks("FILE1").Worksheets("CONSTANTS").Range(" I11")

.Range("B2").Value2 = 1
.Range("B3").Value2 = 2
.Range("B2:B3").AutoFill .Range("B2").Resize(lastrow - 1)
End With


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Frank" wrote in message
...
Hi,

I have the following script in vb:
Dim LNID as range
Dim i as range
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set LNID = Workbooks("FILE1").Worksheets("CONSTANTS").Range(" I11")

Do
LNID = LNID + 1
Set i = Range("B2:B" & LNID)
LNID.Copy i
Loop Until LNID = LastRow

LNID is a constant (= 0) What I want is to add a line number to Column B.
So
in Cell B2 there should be a 1 in there and in cell B3 a 3 should be
copied.
Now all the cells have the same number (there are 200 lines in column C)
so
the number 200 is copied to all cells in column B. it should be 1,2,3,4
etc.
Can anyone help with this?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Do while

Hi Bob,

This works like clockwork!

Thanks a lot!

"Bob Phillips" wrote:

Dim LNID As Range
Dim i As Range
Dim lastrow As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set LNID = Workbooks("FILE1").Worksheets("CONSTANTS").Range(" I11")

.Range("B2").Value2 = 1
.Range("B3").Value2 = 2
.Range("B2:B3").AutoFill .Range("B2").Resize(lastrow - 1)
End With


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Frank" wrote in message
...
Hi,

I have the following script in vb:
Dim LNID as range
Dim i as range
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set LNID = Workbooks("FILE1").Worksheets("CONSTANTS").Range(" I11")

Do
LNID = LNID + 1
Set i = Range("B2:B" & LNID)
LNID.Copy i
Loop Until LNID = LastRow

LNID is a constant (= 0) What I want is to add a line number to Column B.
So
in Cell B2 there should be a 1 in there and in cell B3 a 3 should be
copied.
Now all the cells have the same number (there are 200 lines in column C)
so
the number 200 is copied to all cells in column B. it should be 1,2,3,4
etc.
Can anyone help with this?






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



All times are GMT +1. The time now is 09:37 AM.

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"