AutoFill in Selection Range Method

aejaz7

New Member
Joined
Nov 6, 2018
Messages
20
VBA Code:
Sub demo()

Dim myRange As Range
Set myRange = Selection
myRange.Cells(1, 10).Select
ActiveCell.FormulaR1C1 = "=test" & "(RC[-9])"
Selection.AutoFill Destination:=Range("RC[-9]:RC" & Range("Selection" & Rows.count).End(xlUp).Row), Type:=xlFillDefault

End Sub

ABCDEFGHIJ
Text1
#VALUE!​
Text2
Text10
Text1

Autofill in selection, selection is range("A1:A4") in this demo file.
range is selection like range("A1:A4") or may be any then enter formula which depending first cell of selection.Test is function formula.
but i want to autofill test function cell till last cell of selection row.
Is that possible?

Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try this
VBA Code:
Sub demo()
  Dim r As Range
  Range("A1:A4").Select 'selection is range("A1:A4") in this demo file.
  Set r = Selection
  r.Offset(, 9).FormulaR1C1 = "=""test"" & RC[-9]"
End Sub

Or this
VBA Code:
Sub demo2()
  Dim r As Range
  Range("A1").Select  'one cell
  Set r = Selection
  r.Offset(, 9).FormulaR1C1 = "=""test"" & RC[-9]"
  r.Offset(, 9).AutoFill r.Offset(, 9).Resize(r.Cells(Rows.Count).End(3).Row), xlFillDefault
End Sub
 
Upvote 0
Try this
VBA Code:
Sub demo()
  Dim r As Range
  Range("A1:A4").Select 'selection is range("A1:A4") in this demo file.
  Set r = Selection
  r.Offset(, 9).FormulaR1C1 = "=""test"" & RC[-9]"
End Sub

Or this
VBA Code:
Sub demo2()
  Dim r As Range
  Range("A1").Select  'one cell
  Set r = Selection
  r.Offset(, 9).FormulaR1C1 = "=""test"" & RC[-9]"
  r.Offset(, 9).AutoFill r.Offset(, 9).Resize(r.Cells(Rows.Count).End(3).Row), xlFillDefault
End Sub

Range is not fix, it's depend on selection and will be any.
Thanks for your response.
 
Upvote 0
Try this
VBA Code:
Sub demo()
  Dim r As Range
  Set r = Selection
  r.Offset(, 9).FormulaR1C1 = "=""test"" & RC[-9]"
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,969
Messages
6,175,691
Members
452,667
Latest member
vanessavalentino83

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