View Full Version : [SOLVED:] Need help const a VBA Macro to record 3rd and 4th digits, place in to rght in col B
estatefinds
11-14-2016, 08:07 AM
I have numerical data in column A which consits of 4 digits that make up a combination.
I need to have a macro when ran it records the 3rd and 4th digits of the combinations of column A and copy then to Column B.
Please can any one help?
in the axample i am attaching I did the first handful of combonations to show what it should look like.
Thank you very Much in advance.
Paul_Hossler
11-14-2016, 08:15 AM
A function that does that.
Option Explicit
Function Right2(I As Variant) As Variant
Right2 = CDbl(Right(I, 2))
End Function
estatefinds
11-14-2016, 08:51 AM
I opened the devolper to view code added code and its requested a name of macro I tried everything and I think Im doing sometoing wrong
Paul_Hossler
11-14-2016, 09:22 AM
I opened the devolper to view code added code and its requested a name of macro I tried everything and I think Im doing sometoing wrong
In the VBE, go to [Tools] and [References] and see if any are #Missing. Sometimes I've had the string functions (i.e. Right() ) cause the 'Missing Function' error
Either 1) fix reference or 2) restart computer works
17591
estatefinds
11-14-2016, 09:41 AM
i did what you said above and it still dosnt work I click run and it asks dfor a macro name.
What do I name this so it works. Whhen i Do Name is it puts Sub in front of it
is there a nother way to accomplish this usng VBA?
estatefinds
11-14-2016, 09:43 AM
with the Sub it says"expected sub error"
Paul_Hossler
11-14-2016, 10:26 AM
Right2() is a function and can be used on a worksheet, or called by a VBA Sub
If you're looking to do all the numbers at once, try something like the Sub Right2All
Since the Function only had one line, it was just as easy to include the code in the Sub directly
Option Explicit
Function Right2(I As Variant) As Variant
Right2 = CDbl(Right(I, 2))
End Function
Sub Right2All()
Dim c As Range
For Each c In Range(Range("A20"), Range("A20").End(xlDown)).Cells
c.Value = CDbl(Right(c.Value, 2))
Next
End Sub
Look at the 2 sheets in the attachment
estatefinds
11-14-2016, 11:27 AM
it works great thank you!!!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.