Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Visual Basic - Macros

Hi,

I have two questions regarding macros and how to adapt the VB code so that
the macro can work on any file you may use later.

When recording a macro, if you select a column onto the last record, it only
really works on the current file that you are working on. How can you in VB
change the code so that it adapts to any file knowing that the number of
records will vary?

Also I currently need to copy and paste values of a pivot table onto a blank
sheet. Then I would filter each column on the blanks and add a formula that
the blank cell should equal the cell right above.
Is there a way to do this with a macro? Knowing that the number of records
will vary and that the blank cells will be located in different spots from
one file to another? This would save me some precious time.

Thanks a lot,
Kanga
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Visual Basic - Macros

It all revolves around the last record.

With ACtiveworkbook
Set rng = .Range("A1").Resize(Cells(Rows.Count,"A"),End(xlUp ).Row)
End With

will create a range object of the correct amount of data in column A, which
you can then work on in your code.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Kanga" wrote in message
...
Hi,

I have two questions regarding macros and how to adapt the VB code so that
the macro can work on any file you may use later.

When recording a macro, if you select a column onto the last record, it

only
really works on the current file that you are working on. How can you in

VB
change the code so that it adapts to any file knowing that the number of
records will vary?

Also I currently need to copy and paste values of a pivot table onto a

blank
sheet. Then I would filter each column on the blanks and add a formula

that
the blank cell should equal the cell right above.
Is there a way to do this with a macro? Knowing that the number of records
will vary and that the blank cells will be located in different spots from
one file to another? This would save me some precious time.

Thanks a lot,
Kanga



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Visual Basic - Macros

Excellent! Thanks a lot!

"Bob Phillips" wrote:

It all revolves around the last record.

With ACtiveworkbook
Set rng = .Range("A1").Resize(Cells(Rows.Count,"A"),End(xlUp ).Row)
End With

will create a range object of the correct amount of data in column A, which
you can then work on in your code.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Kanga" wrote in message
...
Hi,

I have two questions regarding macros and how to adapt the VB code so that
the macro can work on any file you may use later.

When recording a macro, if you select a column onto the last record, it

only
really works on the current file that you are working on. How can you in

VB
change the code so that it adapts to any file knowing that the number of
records will vary?

Also I currently need to copy and paste values of a pivot table onto a

blank
sheet. Then I would filter each column on the blanks and add a formula

that
the blank cell should equal the cell right above.
Is there a way to do this with a macro? Knowing that the number of records
will vary and that the blank cells will be located in different spots from
one file to another? This would save me some precious time.

Thanks a lot,
Kanga




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
Imported Visual Basic Module - Save Macros for use in Excel Pat Adams Excel Discussion (Misc queries) 1 December 2nd 09 09:44 PM
Visual Basic Macros Mia Skier Excel Discussion (Misc queries) 3 June 8th 08 04:12 AM
Visual Basic Macros, relative position [email protected] Charts and Charting in Excel 3 November 14th 06 11:33 PM
how to write visual basic macros Ken Michaels Excel Programming 1 November 2nd 04 03:38 PM
creating an exe file with visual basic (installation file for Macros and Userforms) [email protected] Excel Programming 3 August 5th 04 10:16 AM


All times are GMT +1. The time now is 02:36 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"