AndyPandy27
Board Regular
- Joined
- Jul 17, 2012
- Messages
- 142
Hi All,
I'm very new to VBA, but have been experimenting to get a bit better, however I'm stuck and would greatly appreciate some help.
I have ~85,000 rows of data in a "Master Price List", with Product Codes listed in B5:B85000.
However, some of the Product Codes, all of varying length, are currently in a custom number format, to ensure leading zeros are displayed, where applicable. The customer number format is:
In order to convert these to text as "quickly" as possible (please let me know if I am doing this all wrong!), I have written the following VBA:
This works to convert the numbers to text, but it removes the leading zero for those codes which currently have it added based on my custom number format.
Is there any way of being able to amend the above code, to ensure that the numbers which need to have a leading zero, continue to do so?
The criteria for which cells need a leading zero are as follows:
1. The cell in Column G of the same row as the Product Code in Column B = 50
2. The length of the Product Code in Column B = 6
Please let me know if you need any further information from me.
Many thanks,
AP
I'm very new to VBA, but have been experimenting to get a bit better, however I'm stuck and would greatly appreciate some help.
I have ~85,000 rows of data in a "Master Price List", with Product Codes listed in B5:B85000.
However, some of the Product Codes, all of varying length, are currently in a custom number format, to ensure leading zeros are displayed, where applicable. The customer number format is:
Code:
[>9999]000000;General
In order to convert these to text as "quickly" as possible (please let me know if I am doing this all wrong!), I have written the following VBA:
Code:
Sub SingleQuote()
For Each Cell In Selection
If Not Cell.HasFormula Then
Cell.Value = Chr(39) & Cell.Value
End If
Next Cell
End Sub
This works to convert the numbers to text, but it removes the leading zero for those codes which currently have it added based on my custom number format.
Is there any way of being able to amend the above code, to ensure that the numbers which need to have a leading zero, continue to do so?
The criteria for which cells need a leading zero are as follows:
1. The cell in Column G of the same row as the Product Code in Column B = 50
2. The length of the Product Code in Column B = 6
Please let me know if you need any further information from me.
Many thanks,
AP