help to create a Macro

chippymark

Board Regular
Joined
Aug 2, 2007
Messages
50
Hi all,
I need help to create a Macro which I can assign to a button which will achieve the following:
Column A already contains random numbers from zero to 100
Column B Contains a list of names
What I am trying to achieve is if there is a Number in column ‘A’ I want to insert the same number of X’s in the same Row starting at Column ‘C’
See below example:
……A……….B………..C………..D………..E…………F………..G………H…………I
1….0…… James
2....0…… Paul
3….3…….Mark…….X…………X…………X
4….5…….Jon……….X…………X…………X………….X………X
5….1…….Tom………X
6….0…….Mick
7….2…….Sam………X…………X
Any help will be greatly appreciated
Regards
Mark
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
Sub FillData()

    Dim i As Long, j As Long, lastRow As Long
    
    lastRow = Range("A1").End(xlDown).Row
    
    For i = 1 To lastRow
        If Cells(i, 1) > 0 Then
            For j = 3 To Cells(i, 1) + 2
                Cells(i, j) = "X"
            Next
        End If
    Next

End Sub
 
Upvote 0
Code:
Sub FillData()

    Dim i As Long, j As Long, lastRow As Long
    
    lastRow = Range("A1").End(xlDown).Row
    
    For i = 1 To lastRow
        If Cells(i, 1) > 0 Then
            For j = 3 To Cells(i, 1) + 2
                Cells(i, j) = "X"
            Next
        End If
    Next

End Sub

Thank you so much... Excellent !!! did exactly what I was looking for.. Cheers :o)
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,877
Members
452,949
Latest member
Dupuhini

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