Solved

remove everything but cell A1 across 500 excel workbooks

Posted on 2015-02-17
13
49 Views
Last Modified: 2015-02-18
i have 500 excel workbooks

column A is of varying length in each one

i would like to delete the values of the entire workbook...except for cell a1

thanks!

==========
Prior related question: http:Q_28618360.html
0
Comment
Question by:finnstone
[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
  • 6
  • 5
13 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 40615118
Are these CSV files or actual Excel workbooks?

So, after the code runs, there is only one non-empty cell in A1 in the first/only sheet?
0
 

Author Comment

by:finnstone
ID: 40615160
csv

exactly - first sheet for all 500 books
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40615289
Wouldn't it be easier to create one workbook and the copy it over the others, replacing them?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 45

Expert Comment

by:aikimark
ID: 40615328
Never mind.  That would only work if all the workbooks were identical.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40615334
Please test this:
Sub Q_28618738()
    Dim strFilename As String
    Dim wkb As Workbook
    Dim wks As Worksheet
    Dim vData As Variant
    Const cPath As String = "C:\Users\AikiMark\Downloads\Q_28618738\"
    
    strFilename = Dir(cPath & "*.csv")
    Do Until Len(strFilename) = 0
        Set wkb = Workbooks.Open(cPath & strFilename)
        Set wks = wkb.Sheets(1)
        vData = wks.Range("A1").Value
        wks.UsedRange.ClearContents
        wks.Range("A1").Value = vData
        wkb.Close True
        strFilename = Dir
    Loop

End Sub

Open in new window

0
 
LVL 23

Expert Comment

by:Danny Child
ID: 40615399
is it just Cell A1 you want to keep, or all cells in Col A?

And do you want to retain the 500 workbooks - ie NOT extract the 500 cell A1's to a single location instead?

if you're looking to build a master list of the contents of A1, and you can get a list of the filenames, you could use a formula like this:
="='C:\folder\["&A1&".xlsx]Sheet1'!$A$1"
where the filename is listed downwards in col A, and this formula is in Col B, for instance.  Obviously, change "folder" to be your actual location.

Then, copy all of Col B, and Paste Special.. Values over Col B.
then, do a Find/Replace for = with = (ie replace every equals sign with another equals sign), which will force Excel to recalcuate the constructed formulae.

If you need a list of the files extracting, we can probably figure that out too...
0
 

Author Comment

by:finnstone
ID: 40615480
Thx this should
0
 

Author Comment

by:finnstone
ID: 40615483
work although not sure if five hundred files overloads
0
 

Author Comment

by:finnstone
ID: 40615485
Question - can you modify your solution to also save the value b1 into the b column so that a1,b1 from every book are only values saved?
0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 40615697
Ok.  Test this:
Sub Q_28618738()
    Dim strFilename As String
    Dim wkb As Workbook
    Dim wks As Worksheet
    Dim vData As Variant
    Const cPath As String = "C:\Users\AikiMark\Downloads\Q_28618738\"
    
    strFilename = Dir(cPath & "*.csv")
    Do Until Len(strFilename) = 0
        Set wkb = Workbooks.Open(cPath & strFilename)
        Set wks = wkb.Sheets(1)
        vData = wks.Range("A1:B1").Value
        wks.UsedRange.ClearContents
        wks.Range("A1:B1").Value = vData
        wkb.Close True
        strFilename = Dir
    Loop

End Sub

Open in new window

0
 

Author Comment

by:finnstone
ID: 40616577
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40616830
don't forget to close this question
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

739 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