Forum Discussion

Gilli2475's avatar
Gilli2475
Copper Contributor
Nov 28, 2023

Loop introduction

Could you kindly correct the following macro code and introduce a loop in it. 

 

Some cells needs to be automatically updated with "Defect". So the userbox asks for the user to specify the range and then the macro update those selected cells with the word "Defect". Currently, my macro doesn't work, even if it works, it will work only one time. How about if the user needs to select multiple times? Loop is needed?

 

 

Sub Defect()

'

' Defect Macro

'

 

'

  

    ActiveCell.FormulaR1C1 = "Defect"

    Selection.AutoFill Destination:=Application.InputBox(prompt:="Enter range", Type:=8)

   

 

End Sub

 

    • Gilli2475's avatar
      Gilli2475
      Copper Contributor
      Thank you, Doug! Much appreciated. This is for excel. The users should be able to use a macro button to input ranges of excel cells that they want "Defect" to be entered.
      For example, a input message box appears and the user specifies cells F112:F115 to be populated with word "Defect" and the macro automatically enters the word "Defect" in the range F112:F115 and the userbox appears again and this time, lets say the user enters the range F120:F129. I wrote a macro code but it's inconsistent.

Resources