Fill column with "X" based of on value of another cell

p9j123

Active Member
Joined
Apr 15, 2014
Messages
288
Office Version
  1. 2013
Platform
  1. Windows
Need help on creating a macro for this scenario, I hope this to automatically run as I change value.

If I enter 5 on C2 the macro should put "X" on D2:H2
If I enter 3 on H3 the macro should put "X" on I3:K3


This i currently what I have but it is hanging for some reason.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
x = ActiveCell.Value
For i = 1 To x
ActiveCell.Offset(-1, i).Value = i
Next i


End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   Application.EnableEvents = False
   Target.Offset(, 1).Resize(, Target.Value).Value = "X"
   Application.EnableEvents = True
End Sub
 
Upvote 0
Thank @Fluff, can we modify so that it runs only if the value is numeric? and only on the specific area let say from Column F to Column Z only/
 
Upvote 0
Are columns F:Z the columns with the numeric value?
 
Upvote 0
Columns F:Z may or may not have a numeric value, I hope we can modify to run only and only if the value entered on F:Z are numeric if not it will just ignore the macro and will not do anything.
 
Last edited:
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("F:Z")) Is Nothing Then
      Application.EnableEvents = False
      If IsNumeric(Target) Then Target.Offset(, 1).Resize(, Target.Value).Value = "X"
      Application.EnableEvents = True
   End If
End Sub
 
Upvote 0
Just what I needed @Fluff, one problem though when I delete a content I am having an error that says "Application-defined or object-defined error"
 
Upvote 0
Swap that line for
Code:
      If Application.IsNumber(Target) Then Target.Offset(, 1).Resize(, Target.Value).Value = "X"
You may also need to run
Code:
Sub chk()
Application.EnableEvents = True
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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