Fill Column with word of choice referencing keyword from worksheet name

Neveidas

New Member
Joined
Oct 6, 2021
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hello, I am trying to fill column A with either Lost(Breach) or Update(Breach) based on the name of the worksheet. One thing to note is that the worksheets are all of the same names, so they are all labelled as Lost (Breached)(Number) and Update(Breached)(Number) so I can't really fill the columns of all the worksheets that I need
1635144332766.png


Is there like a string or variable VBA that i can tie the keywords "Lost" and "Updates" to so that the code will just reference either one of these 2 keywords and fill Column A with the words that i want it to? And how do i go about coding it?

Thank you!
 
So now you have written your own script by modifying my script because you do not like mine. And now you want me to modify your script??
What was wrong with my script?
Please don't get me wrong, I do not mean to offend you, I was just trying to figure out how to fill to the last row with your script. It's not that i do not like your script. I thought we could figure this out together, instead of just solely relying on you to answer my question
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You said:
how to fill to the last row with your script.

What do you mean by last row??? You said column A was empty
and that means fill from A1 to the last row
So if you have data in column A it will overwrite what's in column A
 
Upvote 0
You said:
how to fill to the last row with your script.

What do you mean by last row??? You said column A was empty
and that means fill from A1 to the last row
So if you have data in column A it will overwrite what's in column A
Ah, i'm so sorry, let me attached a image to clear the air
1635153514889.png


I am tryin to fill Column A (empty Column) to the Last row of data, so in this case as long as its levelled with the other rows. Is this better? i really do apologise for the confusion
 
Upvote 0
So if your image is showing data in column B
You want column A filled down as far as as there is data in column B is that correct.
See you should say till last filled cell in column B
 
Upvote 0
So if your image is showing data in column B
You want column A filled down as far as as there is data in column B is that correct.
See you should say till last filled cell in column B
Yes, really sorry, I didn't know how to put it properly in a sentence
 
Upvote 0
Try this:
VBA Code:
Sub Instr_Lost()
'Modified  10/25/2021  5:34:55 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim lastrow As Long


    For i = 1 To Sheets.Count
            If InStr(Sheets(i).Name, "Lost") > 0 Then
                lastrow = Sheets(i).Cells(Rows.Count, "B").End(xlUp).Row
                Sheets(i).Cells(1, 1).Resize(lastrow).Value = "Lost(Breach"
            End If
            
            If InStr(Sheets(i).Name, "Updates") > 0 Then
                lastrow = Sheets(i).Cells(Rows.Count, "B").End(xlUp).Row
                Sheets(i).Cells(1, 1).Resize(lastrow).Value = "Update(Breach)"
            End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Now I remember you saying you had headers.
So try this:
VBA Code:
Sub Instr_Lost()
'Modified  10/25/2021  5:42:57 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim lastrow As Long


    For i = 1 To Sheets.Count
            If InStr(Sheets(i).Name, "Lost") > 0 Then
                lastrow = Sheets(i).Cells(Rows.Count, "B").End(xlUp).Row
                Sheets(i).Cells(2, 1).Resize(lastrow - 1).Value = "Lost(Breach"
            End If
            
            If InStr(Sheets(i).Name, "Updates") > 0 Then
                lastrow = Sheets(i).Cells(Rows.Count, "B").End(xlUp).Row
                Sheets(i).Cells(2, 1).Resize(lastrow - 1).Value = "Update(Breach)"
            End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Now I remember you saying you had headers.
So try this:
VBA Code:
Sub Instr_Lost()
'Modified  10/25/2021  5:42:57 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim lastrow As Long


    For i = 1 To Sheets.Count
            If InStr(Sheets(i).Name, "Lost") > 0 Then
                lastrow = Sheets(i).Cells(Rows.Count, "B").End(xlUp).Row
                Sheets(i).Cells(2, 1).Resize(lastrow - 1).Value = "Lost(Breach"
            End If
           
            If InStr(Sheets(i).Name, "Updates") > 0 Then
                lastrow = Sheets(i).Cells(Rows.Count, "B").End(xlUp).Row
                Sheets(i).Cells(2, 1).Resize(lastrow - 1).Value = "Update(Breach)"
            End If
    Next
Application.ScreenUpdating = True
End Sub
Yupp, this worked as intended, Thank you so much for doing this. I do apologise once again if i have offended you prevously
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,490
Members
448,967
Latest member
visheshkotha

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