Writing to A range using a Macro

sakrams

Board Regular
Joined
Sep 28, 2009
Messages
59
Office Version
  1. 2016
Platform
  1. Windows
Good Afternoon Excel Gurus,


Need your help with a macro please. I have managed to achieve partially what I need, but what I am after is to repeat the same steps for a range selected in a row. A better option would be to give a popup to fill the adjacent cells (60 or 100 cells) or a range manually selected whichever is easy.

Starting point should be the whatever the active cell is. I can copy paste this multiple times in the macro, but looking for a cleaner code.


Please help.

---------------------------------




Sub DDDDXXX()
Selection.Select
ActiveCell.FormulaR1C1 = "D"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "D"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "D"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "D"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "X"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "X"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "X"
End Sub


-------------------

Thanks
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this:
Put some value in active cell.
Select the range you want filled in with active cell value.

Code:
Sub Fill_In_Please()
ActiveCell.AutoFill Destination:=Selection, Type:=xlFillCopy
End Sub
 
Upvote 0
Not totally clear what you want but you could replace the posted code with this.
Code:
Sub DDDDXXX()
    ActiveCell.Resize(, 7).Value = Array("D", "D", "D", "D", "X", "X", "X")
End Sub
 
Upvote 0
Or you can do the same with a MS built in Keyboard command:

1. Select the range you want your value entered into.

2. Enter your value into the activecell
3. Now press Ctrl+Shift+Enter the same value will now be entered into all cells in your section.
 
Upvote 0
Re: Writing to A range using a Macro [SOLVED]

Thank you everyone.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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