VBA: generate column values for 2nd, last row and in-between ( in Excel)

zeno

Board Regular
Joined
Feb 16, 2012
Messages
71
Hello,

I'd like to know if you could please help me with VBA code for generation of row values in 1 column.
I'm looking at how I can write in VBA a macro that generates values in a particular column (say 'x') that has a few hundred rows (of variable length) within a table. I would define these values as follows:

** Step 1:
2nd row in column x: value=1 (1st row of the table is title row)
last row in column x: value=1
all rows in between: value=n

** Step 2:
In addition, I would also need to use the same sign (either positive or negative) for each row in column x that corresponds to the sign of that row from another column 'y'.


** Possible part of solution:
Code:
Dim arr As Variant
    arr = Range("G2", Cells(Rows.coUnt, "G").End(xlUp)).Value
[\code]

In this case I would count the number of rows in column "G".

[COLOR=#333333]Thank you for your help and advice.[/COLOR]
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You haven't stated what your value for n is, I've used the number 2 below, but try:
Rich (BB code):
FillMe()

Dim i as Long

Application.ScreenUpdating = False

i = Range("X" & Rows.Count).End(xlUp).Row
Range("X2, X" & i) = 1
For i = 3 to i - 1
  Range("X" & i) = Sgn(Range("Y" & i)) * 2'You've not stated your value for n
Next i

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,153
Messages
6,129,176
Members
449,491
Latest member
maxim_sivakon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top