?
Solved

Need help in formatting excel cells

Posted on 2014-11-13
8
Medium Priority
?
271 Views
Last Modified: 2014-11-16
Hi Experts,
I have an Access file linked to an excel file for data comparison,
it compares rows from two sheets containing Social Securities, and displays in a report all names from sheetA that does not have matching records in SheetB and vice versa.
The problem I am encountering is that the data in excel file is not consistent, meaning the social is some time typed in with the dashes and some time it comes as numbers, and user changes it to display format as Social, however in Access it will only recognize the text rows while the numbers are shown as #Num!, what is the easiest solution?
0
Comment
Question by:bfuchs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40441244
You can convert to text and replace dashes with somethign like this... If your social security number is in columns a then in columns B u can put this formula +SUBSTITUTE(TEXT(a1;);"-";"")
0
 
LVL 4

Author Comment

by:bfuchs
ID: 40441560
hi,
it gives me an error message,
besides how can I tell users to do that,
I really  need an automation function on my program to perform that,
thanks,
Ben
0
 
LVL 31

Expert Comment

by:gowflow
ID: 40444161
Could you pls post a sample Excel where you have the problem and will fix it for you ?
gowflow
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 81

Expert Comment

by:byundt
ID: 40445259
Ben,
Here is a macro that will convert social security numbers into text so it can be imported into Access. Install the macro in a regular module sheet, then select your data and run the macro.

As written, the macro assumes your data is in a single column. Text representations of social security numbers (where the hyphens were already typed in) will be left unchanged.
Sub SSnumberToText()
Dim v As Variant
Dim rg As Range
Dim i As Long, n As Long
Set rg = Intersect(Selection, ActiveSheet.UsedRange)
v = rg.Value
n = rg.Rows.Count
For i = 1 To n
    If v(i, 1) <> "" Then v(i, 1) = Format(v(i, 1), "000-00-0000;;;@")
Next
rg.Value = v
End Sub

Open in new window


Cheers!

Brad
0
 
LVL 4

Author Comment

by:bfuchs
ID: 40446163
Hi Experts,

@gowflow,
attached is a sample of file.

@byundt,
Sorry for asking this, but I am not familiar with excel coding, is it possible to modify this so I can run it from Access, or perhaps you can give me exact steps how to install/run macros in Excel (2003)?
Also will the code work if there are additional columns besides the Social?

Thanks,
Ben
Book1.xls
0
 
LVL 81

Accepted Solution

by:
byundt earned 2000 total points
ID: 40446200
I revised the code so it could be run from another application and would automatically convert social security numbers in column A of the first worksheet in a specified workbook. As written, Excel is launched, opens the file at a specified path, performs the conversion of column A to text, saves the file and closes the file.
Sub SSnumberToText()
Dim xlApp As Object
Dim wb As Object
Dim v As Variant
Dim rg As Object
Dim i As Long, n As Long
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set wb = xlApp.Workbooks.Open("X:\VBA\Sample '14\Book1Q28561591.xls")   'change path to suit
With wb.Worksheets(1)
    Set rg = .Range("A1")       'First cell with social security number
    Set rg = xlApp.Range(rg, .Cells(.Rows.Count, rg.Column).End(-4162))     '-4162 is the value of xlUp
End With
v = rg.Value
n = rg.Rows.Count
For i = 1 To n
    If v(i, 1) <> "" Then v(i, 1) = Format(v(i, 1), "000-00-0000;;;@")
Next
rg.Value = v
wb.Save
wb.Close SaveChanges:=False
Set wb = Nothing
Set xlApp = Nothing
End Sub

Open in new window

0
 
LVL 81

Expert Comment

by:byundt
ID: 40446210
The original macro cares only about the first column of cells you select before running the macro. It leaves all other columns unchanged. The revised macro assumes the data is in column A of the first worksheet in the workbook; it assumes the data starts in cell A1 and continues until the last cell with data in column A.

To install the original macro in Excel 2003:

1. ALT + F11 to open the VBA Editor
2. Insert...Module to create an empty module sheet
3. Paste the code there
4. ALT + F11 to return to the worksheet
5. Save the file as either .xls or .xlsm file format

To run a macro in Excel:
1. ALT + F8 to display the macro selector
2. Choose the desired macro, then click the Run button

To change macro security so you can run macros in Excel 2003:
1. Open the Tools...Options...Security menu item
2. Click the button for Macro Security
3. Choose the option for "Medium. You can choose whether or not to run potentially unsafe macros."

When you open the workbook, you should get a warning message about macros. Make sure that you respond by telling Excel to Enable macros in that workbook.
0
 
LVL 4

Author Closing Comment

by:bfuchs
ID: 40446242
Great Work,
Thank you!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question