create/copy formula to adjacent cell/s

wgb789

New Member
Joined
Apr 26, 2018
Messages
6
Good morning to all,

I have the following sample data in column "A".
I've only shown 8 rows worth of data which could increase to 3000+, what I want to do is extract the last 4 digits into Column "B" only for the data shown

T/PR/T3B/01PA
T/PR/T3B/01PA
T/PR/T3B/01PA
T/PR/T3B/01PA
T/PR/T3B/01PA
T/PR/T3B/01PB
T/PR/T3B/01PB
T/PR/T3B/01PB


<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>
I can create VBA to copy a formulainto "B1" what I can't get my head round is to copy only where data exists in column "A".
This is part of a larger VBA exercise and this is the stumbling block.

As you may have guessed I am a complete novice at VBA so any help would be much appreciated.
Thanks in advance.
Bill.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try this:
Code:
[LEFT][COLOR=#222222][FONT=Tahoma]Sub Copy_Over()[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]'Modified  8/14/2018  6:12:28 AM  EDT[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]Application.ScreenUpdating = False[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]Dim i As Long[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]Dim Lastrow As Long[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]Lastrow = Cells(Rows.Count, "A").End(xlUp).Row[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]For i = 1 To Lastrow[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]    If Cells(i, 1).Value <> "" Then Cells(i, "B").Value = Right(Cells(i, 1), 4)[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]Next[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]Application.ScreenUpdating = True[/FONT][/COLOR]
[COLOR=#222222][FONT=Tahoma]End Sub[/FONT][/COLOR][/LEFT]
 
Last edited:
Upvote 0
A couple of other approaches to also consider if you want.
I have assumed that there is a heading row and the data you want to act on starts at row 2. If it does start in row 1 then change "A2" to "A1" in my codes.

If the data in column A is always formatted like your samples, and you want to extract what is after the last "/", then you could try this
Code:
Sub LastPart1()
  Application.ScreenUpdating = False
  With Range("A2", Range("A" & Rows.Count).End(xlUp)).Offset(, 1)
    .Value = .Offset(, -1).Value
    .Replace What:="*/", Replacement:="", LookAt:=xlPart
  End With
  Application.ScreenUpdating = True
End Sub

If the data could be more variable & you want the last 4 characters
Code:
Sub LastPart2()
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    .Offset(, 1).Value = Evaluate(Replace("if(#="""","""",right(#,4))", "#", .Address))
  End With
End Sub
 
Upvote 0
Thank you both ("My answer is this" and "Peter_SSs") in this instance I have used "my answer is this" code and it worked perfectly.
Again many thanks for your very prompt replies
Bill.
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
Thank you both ("My answer is this" and "Peter_SSs") in this instance I have used "my answer is this" code and it worked perfectly.
Again many thanks for your very prompt replies
Bill.
 
Upvote 0
Thank you both ("My answer is this" and "Peter_SSs") in this instance I have used "my answer is this" code and it worked perfectly.
Again many thanks for your very prompt replies
Bill.
You're welcome. Glad you got something you are happy with. :)
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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