ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Quick VB Help (https://www.excelbanter.com/excel-programming/287903-quick-vbulletin-help.html)

April

Quick VB Help
 
I need help writing some vb script.... I know that it is
not that hard, I am just having a brain freeze today and
need help. Here is what I have... 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.

Thanks, April

pikus

Quick VB Help
 
Try this:

lrow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
For x = 2 To lrow
If Worksheets(1).Cells(x, 1).Value < "" Then
nam = Worksheets(1).Cells(x, 2).Value
y = x
Do
y = y + 1
Loop Until Worksheets(1).Cells(y + 1, 1).Value < "" Or _
y = lrow
For z = x + 1 To y
Worksheets(1).Cells(z, 2).Value = nam
Next z
End If
Next x

- Piku

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


No Name

Quick VB Help
 
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
-----Original Message-----
Try this:

lrow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
For x = 2 To lrow
If Worksheets(1).Cells(x, 1).Value < "" Then
nam = Worksheets(1).Cells(x, 2).Value
y = x
Do
y = y + 1
Loop Until Worksheets(1).Cells(y + 1, 1).Value < "" Or _
y = lrow
For z = x + 1 To y
Worksheets(1).Cells(z, 2).Value = nam
Next z
End If
Next x

- Pikus


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

.


pikus

Quick VB Help
 
Did you try what I gave you? - Pikus


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


April

Quick VB Help
 
Yes, instead of filling down what was in ColumnA, it
deleted what was in Column B.
-----Original Message-----
Did you try what I gave you? - Pikus


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

.



All times are GMT +1. The time now is 02:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com