Fill Right

vini1508

New Member
Joined
Feb 8, 2016
Messages
29
Hii,
We can autofill columns by double clicking on them till the last active row...it is done downwards.. i want a macro that will fill to right but on click of button not by dragging..
for example:-
If in sheet, in 1st row i have inserted 1,2,3,4
and in 2nd row if i insert only 3 and 6
and in 3rd row if i inserted only March
given below

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]3[/TD]
[TD]6[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]March[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

after clicking on macro i want that it should auto fill the rows upto the the last column i.e column D


[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]3[/TD]
[TD]6[/TD]
[TD]9[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]March[/TD]
[TD]April[/TD]
[TD]May[/TD]
[TD]June[/TD]
[/TR]
</tbody>[/TABLE]



I dont have any idea how to achive his pls help me
 
I'm not following what you want.
Sounds like you want 20 or more if statements.
If row 1 column A =1 and if row 1 column B =2 and if row 1 column c =3 and if row 1 column 4 =4
and if row 2 column 1 =3 and if row 2 column 2 = 6
and if row 3 column 1 = March
then do this.

I don't see how this can really be what you want.
 
Upvote 0
where will the last active cell be for each row ??
Will filling row 1 or 2 or 3 affect where the last activecell for each row occurs ?
Have you tried recording a macro to do this ??
AND
if the criteria for each row is different then each row will need to be addressed differently ??
 
Upvote 0
See if this does what you want.
Test in a copy of your workbook.

Rich (BB code):
Sub FR()
  Dim lc As Long, r As Long
  
  Application.ScreenUpdating = False
  lc = Cells(1, Columns.Count).End(xlToLeft).Column
  For r = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    With Range("A" & r, Cells(r, Columns.Count).End(xlToLeft))
      .AutoFill Destination:=.Resize(, lc), Type:=xlFillDefault
    End With
  Next r
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
thanks every one for your replies...
Peter_SSs your code is not working in my sheet ..thank you


I'm Really sorry for the confusion i created...

in simple way row 1 consist of numbers from 1 to any number here in example its 4
in row 2 if march is inserted and then that cell is selected and button is presssed then it should automatically fill the remaining columns with april, may and june.

[TABLE="class: cms_table, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]March[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

i want to know how to achieve this

[TABLE="class: cms_table, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]March[/TD]
[TD]April[/TD]
[TD]May[/TD]
[TD]June[/TD]
[/TR]
</tbody>[/TABLE]

I'm sorry if i'm still not able to wirte it down right...
 
Upvote 0
Peter_SSs i tried your code in new wrokbook with new data this time it worked... thank you

now another problem is that if my data does not start from row1 or column 1 then it does not work... please help
 
Upvote 0
Peter_SSs i tried your code in new wrokbook with new data this time it worked... thank you
That's a good start. :)

now another problem is that if my data does not start from row1 or column 1 then it does not work... please help
That isn't surprising as I wrote the code for the information that you gave. Remember, I am not looking at your worksheet, so I can only use what information you give. ;)

So where does the data start?
- What is the first column?
- what row do we use to work out how far right to fill (the header row)?
- what is the first row with actual data to fill right?
 
Upvote 0

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