VB Code problem.

books4cars

Board Regular
Joined
Apr 12, 2007
Messages
200
I use the following vb code every day in excel:

Sub prop()
Dim rng1 As Range, c As Range
Set rng1 = Intersect(ActiveSheet.UsedRange, [A:G,I:O,Q:IV])
If Not rng1 Is Nothing Then
For Each c In rng1
c.Value = WorksheetFunction.Proper(c.Value)
Next
End If
[P:P].Replace "non", ""
[P:P].Replace "select...", ""
[e:e,n:n].Replace "P.O.", "PO"
[e:e,n:n].Replace "P. O.", "PO"
[e:e,n:n].Replace "p o", "PO"
[y:y].Replace " ", ""
[y:y].Replace "-", ""

Do
Set c = Cells.Find(" ")
If Not c Is Nothing Then Cells.Replace " ", " "
Loop Until c Is Nothing

For Each c In Intersect(ActiveSheet.UsedRange, [i:i,q:q])
If c Like "*Us*" Then c.Offset(, 1) = Left(c.Offset(, 1), 5)
Next

End Sub



I just added the two lines of code for column Y to remove spaces and hyphens from all cells in that column. When I run the code, the cells that are affected show notation like this 4.85321E+15 instead of a long number. All the cells are formatted to text before I run the code. How can I get just the numbers and not the notation?
Thx
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Mordecai

Perhaps if you explained the purpose of the code you might get some responses.

It might also help to post some sample data, both before and after.:)

By the way I really wouldn't recommend using [] notation when referring to ranges.

And it might be an idea to explicitly reference the worksheet rather than using ActiveSheet.
 
Upvote 0
The numbers are credit cards which are on a sheet with other customer info. I am simply trying to remove all hyphens and spaces from that column.

As for not using the "[]" when refrecing a column, what do you suggest as an alternative?
 
Upvote 0
Mordecai

It really would be helpful to see some sample data.

If you are worried about confidentiality then just create some sample data.

As to not using [], why not use Range("A:A") etc and qualify the worksheet(s) like this.
Code:
Worksheets("Sheet1").Range("A:A")
That should ensure that the correct range on the correct worksheet is being used in the code.

If you use [] without any worksheet reference then VBA will refer to the range it considers to be the active sheet.

And that might not be the one you want.:)
 
Upvote 0
SO I should replace

[y:y].Replace "-", ""

with

Worksheets("Sheet1").Range("y:y").Replace "-", ""
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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