VBA Code to Fill Cells based on newly entered Cell

Froesiie

New Member
Joined
Mar 17, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
The obligatory, I'm new to VBA.

I've been using Flow/Power Automate to move an email into a workbook and I'm running formulas to parse it into Different Cells on the same line. (yes I know i can use an email parser but it wasn't working properly and this is just easier.)
Without going into huge details, every time a new email is added to Column A I want it to run all the formulas on the same line.
Such as:
(A2) = Email
(B2) =RIGHT(A$2, LEN(A$2)-SEARCH("Device",A$2)-7)
(C2) =RIGHT(A$2, LEN(A$2)-SEARCH("Net New Device:",A$2)-15)
(A3) = New Email
(B3) =RIGHT(A$3, LEN(A$3)-SEARCH("Device",A$3)-7)
(C3) =RIGHT(A$3, LEN(A$3)-SEARCH("Net New Device:",A$3)-15)
Etc..
I need this in VBA rather than just formulas so I can use Power Automate to move the info from the cells elsewhere.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Welcome to the Board!

So, do you just want it so that whenver an entry is made in column A, the formulas in cells B2 and C2 are copied down to those rows?
If so, here is cde that will do what you want automatically.
Simply right-click on the sheet tab name at the bottom of your screen, select "View Code", and paste this code in the VBA Editor window that pops up.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    
    Set rng = Intersect(Target, Range("A:A"))
    
    If Not rng Is Nothing Then
        Application.EnableEvents = False
        For Each cell In rng
            Range("B2:C2").Copy Cells(cell.Row, "B")
        Next cell
        Application.EnableEvents = True
    End If
        
End Sub
This will work, as long as you have Macros/VBA enabled.
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,237
Members
448,555
Latest member
RobertJones1986

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