Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro problem

Using Excel 2000:

I used the macro recorder to design the follwoing macro then I went in with
help from books and modified it to try and attempt what I want it to do. I
want ed to try and repeat a process just using a different file and it
doesn't seem to work. Let me show you the macro and show the part that
doesn't work:

Private Sub CommandButton1_Click()



Dim Controls(20)



Sheets("Population Download").Cells.Clear

Sheets("Demographics Download").Cells.Clear

ChDir "c:\Documents and settings\pete.sitetech03\desktop\Demographic
Downloads"

FileToOpenPop = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")

Workbooks.Open FileToOpenPop

Worksheets(1).Range("A1:J80").Copy

ActiveWorkbook.Close False

Windows("Quick Facts 2004.xlt").Activate

ThisWorkbook.Sheets("population download").Range("A1").PasteSpecial
Paste:=xlPasteAll

Application.CutCopyMode = False

ChDir "c:\Documents and settings\pete.sitetech03\desktop\Demographic
Downloads"

FileToOpenDem = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")

Workbooks.Open FileToOpenDem

Worksheets(1).Range("A1:J80").Copy

ActiveWorkbook.Close False

Windows("Quick Facts 2004.xlt").Activate

ThisWorkbook.Sheets("demographics download").Range("A1").PasteSpecial
Paste:=xlPasteAll

Application.CutCopyMode = False



Up to this point everything works the next section is the first part of
copying and pasting info to another file and this part works



' Gets date from population datasheet

Sheets("population db").Select

ThisWorkbook.Sheets("population db").Range("A2").Select

ThisWorkbook.Sheets("population db").Range("a2:dk2").Select

Selection.Copy

ChDir "c:\Documents and settings\pete.sitetech03\my documents"

Workbooks.Open "c:\Documents and settings\pete.sitetech03\my
documents\populationdb.xls"

Sheets("sheet1").Range("A1").Select

ActiveCell.End(xlDown)(2).Select

Selection.PasteSpecial Paste:=xlValues

Selection.PasteSpecial Paste:=xlFormats

Sheets("sheet1").Range("A1").Select

Workbooks("populationdb.XLS").Close SaveChanges:=True

Application.CutCopyMode = False





This is the section where I want to do the same procedure from the section
above just to a different file. It seems to work up to the line:
ActiveCell.End(xlDown)(2).Select





' Get data from demographic datasheet

Sheets("demographic db").Select

ThisWorkbook.Sheets("demographic db").Range("A2").Select

ThisWorkbook.Sheets("demographic db").Range("a2:bx2").Select

Selection.Copy

ChDir "c:\Documents and settings\pete.sitetech03\my documents"

Workbooks.Open "c:\Documents and settings\pete.sitetech03\my
documents\demographicdb.xls"

Sheets("sheet1").Range("A1").Select

Range("A1").Activate

ActiveCell.End(xlDown)(2).Select

Selection.PasteSpecial Paste:=xlValues

Selection.PasteSpecial Paste:=xlFormats

Sheets("sheet1").Range("A1").Select

Workbooks("demographicdb.XLS").Close SaveChanges:=True

Application.CutCopyMode = False

' ActiveWorkbook.Close False





End Sub



Any help will be appreciated.



Pete Provencher


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Macro problem

Pete,

Two thoughts:

You may not have enough cells filled in column A, in which case this

Sheets("sheet1").Range("A1").Select

Range("A1").Activate

ActiveCell.End(xlDown)(2).Select


would try to take you off the sheet.

Try changing that to this:

Sheets("Sheet1").Select
Range("A65536").End(xlUp)(2).Select

Also, opening a workbook will clear the copy buffer. If your paste is
failing, you need to open the workbook, go back to the workbook from where
you wan to copy, do the copy, return to the newly opened workbook, and then
do the paste.

HTH,
Bernie
MS Excel MVP

" Pete Provencher" wrote in message
...
Using Excel 2000:

I used the macro recorder to design the follwoing macro then I went in

with
help from books and modified it to try and attempt what I want it to do. I
want ed to try and repeat a process just using a different file and it
doesn't seem to work. Let me show you the macro and show the part that
doesn't work:

Private Sub CommandButton1_Click()



Dim Controls(20)



Sheets("Population Download").Cells.Clear

Sheets("Demographics Download").Cells.Clear

ChDir "c:\Documents and settings\pete.sitetech03\desktop\Demographic
Downloads"

FileToOpenPop = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")

Workbooks.Open FileToOpenPop

Worksheets(1).Range("A1:J80").Copy

ActiveWorkbook.Close False

Windows("Quick Facts 2004.xlt").Activate

ThisWorkbook.Sheets("population download").Range("A1").PasteSpecial
Paste:=xlPasteAll

Application.CutCopyMode = False

ChDir "c:\Documents and settings\pete.sitetech03\desktop\Demographic
Downloads"

FileToOpenDem = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")

Workbooks.Open FileToOpenDem

Worksheets(1).Range("A1:J80").Copy

ActiveWorkbook.Close False

Windows("Quick Facts 2004.xlt").Activate

ThisWorkbook.Sheets("demographics download").Range("A1").PasteSpecial
Paste:=xlPasteAll

Application.CutCopyMode = False



Up to this point everything works the next section is the first part of
copying and pasting info to another file and this part works



' Gets date from population datasheet

Sheets("population db").Select

ThisWorkbook.Sheets("population db").Range("A2").Select

ThisWorkbook.Sheets("population db").Range("a2:dk2").Select

Selection.Copy

ChDir "c:\Documents and settings\pete.sitetech03\my documents"

Workbooks.Open "c:\Documents and settings\pete.sitetech03\my
documents\populationdb.xls"

Sheets("sheet1").Range("A1").Select

ActiveCell.End(xlDown)(2).Select

Selection.PasteSpecial Paste:=xlValues

Selection.PasteSpecial Paste:=xlFormats

Sheets("sheet1").Range("A1").Select

Workbooks("populationdb.XLS").Close SaveChanges:=True

Application.CutCopyMode = False





This is the section where I want to do the same procedure from the section
above just to a different file. It seems to work up to the line:
ActiveCell.End(xlDown)(2).Select





' Get data from demographic datasheet

Sheets("demographic db").Select

ThisWorkbook.Sheets("demographic db").Range("A2").Select

ThisWorkbook.Sheets("demographic db").Range("a2:bx2").Select

Selection.Copy

ChDir "c:\Documents and settings\pete.sitetech03\my documents"

Workbooks.Open "c:\Documents and settings\pete.sitetech03\my
documents\demographicdb.xls"

Sheets("sheet1").Range("A1").Select

Range("A1").Activate

ActiveCell.End(xlDown)(2).Select

Selection.PasteSpecial Paste:=xlValues

Selection.PasteSpecial Paste:=xlFormats

Sheets("sheet1").Range("A1").Select

Workbooks("demographicdb.XLS").Close SaveChanges:=True

Application.CutCopyMode = False

' ActiveWorkbook.Close False





End Sub



Any help will be appreciated.



Pete Provencher




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro problem

I'm afraid that didn't work. It still goes to A1 and doesn't go to the first
empty row which is A2. I have column names in row 1. I don't get an error
wit your changes but it still doesn't work. I don't think it is pasting as
it doesn't go to the first blank row. The data that is copied is in the
clipboard. I can't figure out why it works with the populationdb file.

Pete Provencher

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Pete,

Two thoughts:

You may not have enough cells filled in column A, in which case this

Sheets("sheet1").Range("A1").Select

Range("A1").Activate

ActiveCell.End(xlDown)(2).Select


would try to take you off the sheet.

Try changing that to this:

Sheets("Sheet1").Select
Range("A65536").End(xlUp)(2).Select

Also, opening a workbook will clear the copy buffer. If your paste is
failing, you need to open the workbook, go back to the workbook from where
you wan to copy, do the copy, return to the newly opened workbook, and

then
do the paste.

HTH,
Bernie
MS Excel MVP

" Pete Provencher" wrote in message
...
Using Excel 2000:

I used the macro recorder to design the follwoing macro then I went in

with
help from books and modified it to try and attempt what I want it to do.

I
want ed to try and repeat a process just using a different file and it
doesn't seem to work. Let me show you the macro and show the part that
doesn't work:

Private Sub CommandButton1_Click()



Dim Controls(20)



Sheets("Population Download").Cells.Clear

Sheets("Demographics Download").Cells.Clear

ChDir "c:\Documents and settings\pete.sitetech03\desktop\Demographic
Downloads"

FileToOpenPop = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")

Workbooks.Open FileToOpenPop

Worksheets(1).Range("A1:J80").Copy

ActiveWorkbook.Close False

Windows("Quick Facts 2004.xlt").Activate

ThisWorkbook.Sheets("population download").Range("A1").PasteSpecial
Paste:=xlPasteAll

Application.CutCopyMode = False

ChDir "c:\Documents and settings\pete.sitetech03\desktop\Demographic
Downloads"

FileToOpenDem = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")

Workbooks.Open FileToOpenDem

Worksheets(1).Range("A1:J80").Copy

ActiveWorkbook.Close False

Windows("Quick Facts 2004.xlt").Activate

ThisWorkbook.Sheets("demographics

download").Range("A1").PasteSpecial
Paste:=xlPasteAll

Application.CutCopyMode = False



Up to this point everything works the next section is the first part of
copying and pasting info to another file and this part works



' Gets date from population datasheet

Sheets("population db").Select

ThisWorkbook.Sheets("population db").Range("A2").Select

ThisWorkbook.Sheets("population db").Range("a2:dk2").Select

Selection.Copy

ChDir "c:\Documents and settings\pete.sitetech03\my documents"

Workbooks.Open "c:\Documents and settings\pete.sitetech03\my
documents\populationdb.xls"

Sheets("sheet1").Range("A1").Select

ActiveCell.End(xlDown)(2).Select

Selection.PasteSpecial Paste:=xlValues

Selection.PasteSpecial Paste:=xlFormats

Sheets("sheet1").Range("A1").Select

Workbooks("populationdb.XLS").Close SaveChanges:=True

Application.CutCopyMode = False





This is the section where I want to do the same procedure from the

section
above just to a different file. It seems to work up to the line:
ActiveCell.End(xlDown)(2).Select





' Get data from demographic datasheet

Sheets("demographic db").Select

ThisWorkbook.Sheets("demographic db").Range("A2").Select

ThisWorkbook.Sheets("demographic db").Range("a2:bx2").Select

Selection.Copy

ChDir "c:\Documents and settings\pete.sitetech03\my documents"

Workbooks.Open "c:\Documents and settings\pete.sitetech03\my
documents\demographicdb.xls"

Sheets("sheet1").Range("A1").Select

Range("A1").Activate

ActiveCell.End(xlDown)(2).Select

Selection.PasteSpecial Paste:=xlValues

Selection.PasteSpecial Paste:=xlFormats

Sheets("sheet1").Range("A1").Select

Workbooks("demographicdb.XLS").Close SaveChanges:=True

Application.CutCopyMode = False

' ActiveWorkbook.Close False





End Sub



Any help will be appreciated.



Pete Provencher






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro problem

It did work. I must have done something wqrong the first time and I wrote it
on row 65536. Once I cleared that out it worked as you said. Thanks alot. It
was starting to bug my brain.

Pete Provencher

" Pete Provencher" wrote in message
...
I'm afraid that didn't work. It still goes to A1 and doesn't go to the

first
empty row which is A2. I have column names in row 1. I don't get an error
wit your changes but it still doesn't work. I don't think it is pasting as
it doesn't go to the first blank row. The data that is copied is in the
clipboard. I can't figure out why it works with the populationdb file.

Pete Provencher

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Pete,

Two thoughts:

You may not have enough cells filled in column A, in which case this

Sheets("sheet1").Range("A1").Select

Range("A1").Activate

ActiveCell.End(xlDown)(2).Select


would try to take you off the sheet.

Try changing that to this:

Sheets("Sheet1").Select
Range("A65536").End(xlUp)(2).Select

Also, opening a workbook will clear the copy buffer. If your paste is
failing, you need to open the workbook, go back to the workbook from

where
you wan to copy, do the copy, return to the newly opened workbook, and

then
do the paste.

HTH,
Bernie
MS Excel MVP

" Pete Provencher" wrote in message
...
Using Excel 2000:

I used the macro recorder to design the follwoing macro then I went

in
with
help from books and modified it to try and attempt what I want it to

do.
I
want ed to try and repeat a process just using a different file and it
doesn't seem to work. Let me show you the macro and show the part that
doesn't work:

Private Sub CommandButton1_Click()



Dim Controls(20)



Sheets("Population Download").Cells.Clear

Sheets("Demographics Download").Cells.Clear

ChDir "c:\Documents and

settings\pete.sitetech03\desktop\Demographic
Downloads"

FileToOpenPop = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")

Workbooks.Open FileToOpenPop

Worksheets(1).Range("A1:J80").Copy

ActiveWorkbook.Close False

Windows("Quick Facts 2004.xlt").Activate

ThisWorkbook.Sheets("population

download").Range("A1").PasteSpecial
Paste:=xlPasteAll

Application.CutCopyMode = False

ChDir "c:\Documents and

settings\pete.sitetech03\desktop\Demographic
Downloads"

FileToOpenDem = Application.GetOpenFilename("Excel Files (*.xls),
*.xls")

Workbooks.Open FileToOpenDem

Worksheets(1).Range("A1:J80").Copy

ActiveWorkbook.Close False

Windows("Quick Facts 2004.xlt").Activate

ThisWorkbook.Sheets("demographics

download").Range("A1").PasteSpecial
Paste:=xlPasteAll

Application.CutCopyMode = False



Up to this point everything works the next section is the first part

of
copying and pasting info to another file and this part works



' Gets date from population datasheet

Sheets("population db").Select

ThisWorkbook.Sheets("population db").Range("A2").Select

ThisWorkbook.Sheets("population db").Range("a2:dk2").Select

Selection.Copy

ChDir "c:\Documents and settings\pete.sitetech03\my documents"

Workbooks.Open "c:\Documents and settings\pete.sitetech03\my
documents\populationdb.xls"

Sheets("sheet1").Range("A1").Select

ActiveCell.End(xlDown)(2).Select

Selection.PasteSpecial Paste:=xlValues

Selection.PasteSpecial Paste:=xlFormats

Sheets("sheet1").Range("A1").Select

Workbooks("populationdb.XLS").Close SaveChanges:=True

Application.CutCopyMode = False





This is the section where I want to do the same procedure from the

section
above just to a different file. It seems to work up to the line:
ActiveCell.End(xlDown)(2).Select





' Get data from demographic datasheet

Sheets("demographic db").Select

ThisWorkbook.Sheets("demographic db").Range("A2").Select

ThisWorkbook.Sheets("demographic db").Range("a2:bx2").Select

Selection.Copy

ChDir "c:\Documents and settings\pete.sitetech03\my documents"

Workbooks.Open "c:\Documents and settings\pete.sitetech03\my
documents\demographicdb.xls"

Sheets("sheet1").Range("A1").Select

Range("A1").Activate

ActiveCell.End(xlDown)(2).Select

Selection.PasteSpecial Paste:=xlValues

Selection.PasteSpecial Paste:=xlFormats

Sheets("sheet1").Range("A1").Select

Workbooks("demographicdb.XLS").Close SaveChanges:=True

Application.CutCopyMode = False

' ActiveWorkbook.Close False





End Sub



Any help will be appreciated.



Pete Provencher








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with macro Dazed and Confused[_2_] New Users to Excel 2 March 7th 09 11:48 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Macro problem [email protected] Excel Discussion (Misc queries) 6 January 2nd 07 09:22 PM
macro problem Kevin Excel Discussion (Misc queries) 1 December 14th 04 10:47 PM


All times are GMT +1. The time now is 01:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"