Adding an X to Column B if Column A is populated

leigh123

New Member
Joined
Jan 11, 2023
Messages
4
Hi, I am new to excel VBA. I am trying to create a VBA macro that will mark an X in Column B for all of the current rows. I am looking for it to count all of the current rows starting with "A5". I've attached a copy of the code that I have and a snip of the spreadsheet that I'm working.


Snip of Spreadsheet:
SortCLINPart Number
1000180510
2000123253
3000225436


Current Code that I have:

Sub Check_All()

Sheets("Material Summary").Activate
Dim MyRange As Range
Dim i As Integer, j As Integer
Set MyRange = Selection
Range("B5").Select
For j = 1 To MyRange.Rows.Count
MyRange.Cells(j, 2) = "X"
Next j
End Sub


I am very new to VBA so any help is appreciated!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Does this do what you want?
VBA Code:
Sub Check_All()

    Dim lr As Long
    
    Sheets("Material Summary").Activate
    
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Populate column B from row 5 to last row
    If lr >= 5 Then
        Range("B5:B" & lr).Value = "X"
    End If

End Sub
 
Upvote 0
Solution
Hi and welcome to MrExcel.

Try:

VBA Code:
Sub Adding_an_X()
  With Range("B5:B" & Range("A" & Rows.Count).End(3).Row)
    .Formula = "=IF(A5<>"""",""X"","""")"
    .Value = .Value
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,130
Messages
6,123,220
Members
449,091
Latest member
jeremy_bp001

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