Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Looping and Filling Info

I need help writing some vb script.... In Column A, every
couple of rows I have a "Identifier" then a couple of
rows of names (Column B) and I need to write code that
will Start at A2 (Or Active Cell) and Do a Select
(xlDown), Offset (-1,0) (Up one Row) and CopyDown, then
select then next identifier and do it again until the
end. For example, Cell A2 to A4 will copy down what is in
A2, A5 to A26 will copy down what is on A5, A27 to A47
will copy down what is in A27.

I have this:

Do
ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.Offset(-1, 0)).Select
Selection.FillDown
Selection.End(xlDown).Select

Loop

The only problem is the offset(-1,0) is not working
right. Say it has A5:A10 Selected, instead of changing
it to A5:A9 with the Offset(-1,0) it is changing it to
A4:A10 or A5:A11, how do I get it to offset up one row
(From the bottom of the select and not from the top).

April

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Looping and Filling Info

April

This doesn't answer your original question, but will do the Autofill for you.

''fill in blanks from cell above
Sub Fill_Blanks()
Dim myRange As Range
Set myRange = Selection
On Error GoTo stopnow
If myRange.Cells.Count = 1 Then
MsgBox "Select a range first."
Else
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=R[-1]C"
Range("B1").Select
End If
stopnow:
End Sub

Gord Dibben Excel MVP

On Tue, 17 Feb 2004 13:39:06 -0800, "April" wrote:

I need help writing some vb script.... In Column A, every
couple of rows I have a "Identifier" then a couple of
rows of names (Column B) and I need to write code that
will Start at A2 (Or Active Cell) and Do a Select
(xlDown), Offset (-1,0) (Up one Row) and CopyDown, then
select then next identifier and do it again until the
end. For example, Cell A2 to A4 will copy down what is in
A2, A5 to A26 will copy down what is on A5, A27 to A47
will copy down what is in A27.

I have this:

Do
ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.Offset(-1, 0)).Select
Selection.FillDown
Selection.End(xlDown).Select

Loop

The only problem is the offset(-1,0) is not working
right. Say it has A5:A10 Selected, instead of changing
it to A5:A9 with the Offset(-1,0) it is changing it to
A4:A10 or A5:A11, how do I get it to offset up one row
(From the bottom of the select and not from the top).

April


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Looping and Filling Info

Gord,

That works but I need something that is more automated.
I have over 8,000 rows that I need to AutoFill! Can I
not get my code to do it?

April
-----Original Message-----
April

This doesn't answer your original question, but will do

the Autofill for you.

''fill in blanks from cell above
Sub Fill_Blanks()
Dim myRange As Range
Set myRange = Selection
On Error GoTo stopnow
If myRange.Cells.Count = 1 Then
MsgBox "Select a range first."
Else
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=R[-1]C"
Range("B1").Select
End If
stopnow:
End Sub

Gord Dibben Excel MVP

On Tue, 17 Feb 2004 13:39:06 -0800, "April"

wrote:

I need help writing some vb script.... In Column A,

every
couple of rows I have a "Identifier" then a couple of
rows of names (Column B) and I need to write code that
will Start at A2 (Or Active Cell) and Do a Select
(xlDown), Offset (-1,0) (Up one Row) and CopyDown, then
select then next identifier and do it again until the
end. For example, Cell A2 to A4 will copy down what is

in
A2, A5 to A26 will copy down what is on A5, A27 to A47
will copy down what is in A27.

I have this:

Do
ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.Offset(-1, 0)).Select
Selection.FillDown
Selection.End(xlDown).Select

Loop

The only problem is the offset(-1,0) is not working
right. Say it has A5:A10 Selected, instead of changing
it to A5:A9 with the Offset(-1,0) it is changing it to
A4:A10 or A5:A11, how do I get it to offset up one row
(From the bottom of the select and not from the top).

April


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Looping and Filling Info

/Me thinks you will like:

z = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count

For x = ActiveCell.Row To z
If Cells(x, 1).Value < "" Then
val1 = Cells(x, 1).Value
Else
Cells(x, 1).Value = val1
End If
Next x

- Pikus


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Looping and Filling Info

OH! and don't forget:

Application.ScreenUpdating = False
z = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count

For x = ActiveCell.Row To z
If Cells(x, 1).Value < "" Then
val1 = Cells(x, 1).Value
Else
Cells(x, 1).Value = val1
End If
Next x
Application.ScreenUpdating = True

- Pikus


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Looping and Filling Info


-----Original Message-----
OH! and don't forget:

Application.ScreenUpdating = False
z = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count

For x = ActiveCell.Row To z
If Cells(x, 1).Value < "" Then
val1 = Cells(x, 1).Value
Else
Cells(x, 1).Value = val1
End If
Next x
Application.ScreenUpdating = True

- Pikus


---
Message posted from http://www.ExcelForum.com/

.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Looping and Filling Info

Thank you, Thank you, Thank you, that worked
perfectly!!!!!



-----Original Message-----
OH! and don't forget:

Application.ScreenUpdating = False
z = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count

For x = ActiveCell.Row To z
If Cells(x, 1).Value < "" Then
val1 = Cells(x, 1).Value
Else
Cells(x, 1).Value = val1
End If
Next x
Application.ScreenUpdating = True

- Pikus


---
Message posted from http://www.ExcelForum.com/

.

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
Move cell info and info in range of cells on new entry abc[_2_] Excel Discussion (Misc queries) 5 February 15th 10 08:21 PM
Copied info from Excel worksheet, but pasted info won't work in fo KRISTENV Excel Discussion (Misc queries) 3 January 8th 09 03:13 PM
Filling a few cells based on the info from another worksheet. Bruce[_2_] Excel Worksheet Functions 5 May 23rd 07 02:32 AM
Pulling a Letter from a cell and filling another cell with info nick s Excel Worksheet Functions 16 November 28th 05 04:10 AM
filling information from one cell and filling another. Dianne Excel Worksheet Functions 1 August 15th 05 08:14 PM


All times are GMT +1. The time now is 01:03 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"