Fill in cell base on another cell value

zermrodrigues

New Member
Joined
Jan 21, 2025
Messages
1
Office Version
  1. 2024
Platform
  1. Windows
Dear all,

I have been trying to adapt a macro to suit my purposes but cannot make the macro to add data on more that once cell. What I want is when the cell value on the column B is "Office" then the macro should write "TAG/IN" on the column F (which I have managed to get) and also "TAG/OUT" on the column N in the same line as the "Office" value shows up. I have been using this macro:

VBA Code:
Sub Fill_F_column()
Dim Rng As Range
Dim T&, Lr&, S$
Application.ScreenUpdating = False
Lr = Range("B" & Rows.Count).End(xlUp).Row
For T = Lr To 2 Step -1
If Range("B" & T) = "Office" And Range("F" & T) = "" Then S = S & ",F" & T
If S <> "" Then
If Len(S) > 240 Or T = 2 Then Range(Mid(S, 2)) = "TAG/IN": S = ""
End If
Next T
Application.ScreenUpdating = True
End Sub

Can anyone halp me with this? Thank you. Kind regards, Jose
 
Last edited by a moderator:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Wen I first looked at what you were wanting I thought a sheet change event script would work.
For example, if you entered "Apple" in any cell in column B "Pie" would be entered in Column C same row.

But when I see in your script you have things like this:
"If Len(S) > 240 Or T = 2 Then Range(Mid(S, 2)) = "TAG/IN": S = """

I have no idea what you're wanting.
Please explain and maybe I can help you.
 
Upvote 0
Welcome to the MrExcel board!

When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block at the bottom of this post has more details. I have added the tags for you this time. 😊

Is this what you mean? Test with a copy of your data.

VBA Code:
Sub Fill_F_and_N_column()
  Dim Rng As Range
  Dim T&, Lr&, S$
 
  Application.ScreenUpdating = False
  Lr = Range("B" & Rows.Count).End(xlUp).Row
  For T = Lr To 2 Step -1
    If Range("B" & T) = "Office" And Range("F" & T) = "" Then S = S & ",F" & T
    If S <> "" Then
      If Len(S) > 240 Or T = 2 Then
        Range(Mid(S, 2)) = "TAG/IN"
        Range(Mid(S, 2)).Offset(, 8).Value = "TAG/OUT"
        S = ""
      End If
    End If
  Next T
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,741
Messages
6,186,763
Members
453,370
Latest member
juliewar

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