Modifying code to Consolidate only 1 column..

D

Darin Kramer

Hi there,

The code below correctly opens however many excel workbooks located
within a sub directory, and copies and pastes the first 4 columns into
another sheet. (end result is you have consolidated the 4 columns into
new sheet)

QUESTION I
I want to modify the code ONLY to copy column 2 into the new sheet, (and
do repetively for all books within the same sub directory) How do I do
so...? (My VB skills are slightly limited.., so not sure which variable
to change....)

Question II
Is there any way to turn off the auto alert when you open a book that
says "Do you want to enable Macros", and the auto alert when you close
the book that says "there is a large amount of data on the clipboard, do
you want it available for later use...?

Thanks!!!!
Regards

Darin

Sub Consolidator

Dim i As Long, sName As String, sh As Worksheet
Dim dest As Range, bk As Workbook
i = 1
sName = Dir("D:\Documents and
Settings\user\Desktop\Projects\Projects_06\Consolidation_test\results\*.
xls")
Do While sName <> ""
Set bk = Workbooks.Open("D:\Documents and
Settings\user\Desktop\Projects\Projects_06\Consolidation_test\results\"
& sName)
Set sh = bk.Worksheets("Answers")
Set dest = ThisWorkbook.Worksheets(1).Cells(1, i)
i = i + 1
sh.Columns(1).Resize(, 2).Copy
dest.PasteSpecial xlValues
dest.PasteSpecial xlFormats
' write name of the workbook in row 1
dest.Value = sName
' close the workbook
bk.Close SaveChanges:=False
sName = Dir()
Loop
ActiveSheet.Select
ActiveSheet.Name = "Consolidated"



End Sub
 
B

Bob Phillips

Looks like 2 columns to me.

Change this

sh.Columns(1).Resize(, 2).Copy

to

sh.Columns(2).Copy


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
B

Bob Phillips

You cannot stop them getting that message without setting your security
setting to low (which is a very bad idea), but you can take some defensive
action.

You can digitally sign the workbook so they don't get the message, or you
can try and make the workbook (seemingly) inoperable if the users disable
macros.

The standard way to approach this is as follows.
- create a worksheet with a message on explaining that for this workbook to
run it needs macros enabled, maybe even a few screenshots
- hide all other worksheets]
- add some code in the Workbook_Open event that un hides the other sheets,
but hides that sheet.


What happens is that if they do not enable macros, they will only see the
warning sheet, telling them how to do it. If the enable macros, it will
startup as the workbook it should be.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top