SonicBoomGolf
Active Member
- Joined
- Aug 7, 2004
- Messages
- 325
I am making a small macro to convert materials outside of SAP into materials that can be recognized by SAP. Here is a sample material transition I am looking to do.
Convert material 1031560 to 000000000001031560
Obviously, outside of SAP those extra zeros have no value so I remove them. However, sometime I have to add them back in when I want to query specific materials in BW.
The code below is getting me very close to where I want to go. All I need to figure out is how to add in a specific number of zeros to the front of a material number.
In the example above, I would have to add 11 zeros and format the number as text in order to get a legit 18 digit material number (in SAP, all our materials are 18 digits long).
Sample material numbers are in column A and the number of characters in the current material are identified in column b. How can I add in the number of zeros needed as I describe above? Thanks for the help in advance.
Sub SAPMaterial()
Dim x As Integer, rng As Range, c As Range
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range("A1:A" & LastRow)
For Each c In rng.Cells
'Materials in SAP are 18 characters long, so 18-number of characters in current material number will identify how many zeros I have to add to get a legit material.
c.Offset(0, 1).Formula = "=len(" & c.Address & ")"
'Not sure what to do here to add in the zeros needed to get to a legit 18 digit material
Next c
End Sub
Convert material 1031560 to 000000000001031560
Obviously, outside of SAP those extra zeros have no value so I remove them. However, sometime I have to add them back in when I want to query specific materials in BW.
The code below is getting me very close to where I want to go. All I need to figure out is how to add in a specific number of zeros to the front of a material number.
In the example above, I would have to add 11 zeros and format the number as text in order to get a legit 18 digit material number (in SAP, all our materials are 18 digits long).
Sample material numbers are in column A and the number of characters in the current material are identified in column b. How can I add in the number of zeros needed as I describe above? Thanks for the help in advance.
Sub SAPMaterial()
Dim x As Integer, rng As Range, c As Range
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range("A1:A" & LastRow)
For Each c In rng.Cells
'Materials in SAP are 18 characters long, so 18-number of characters in current material number will identify how many zeros I have to add to get a legit material.
c.Offset(0, 1).Formula = "=len(" & c.Address & ")"
'Not sure what to do here to add in the zeros needed to get to a legit 18 digit material
Next c
End Sub