Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to delete previous data from 1 macro before running the next?

Hi!
Hope someone can help. I'm sure this is probably very easy for someone. :-)

I have a workbook and 1 tab is called OEM material with about 1000 items
listed and sorted by categories and another tab called Template.

I have created 11 macros that will select certain data by category from the
OEM material tab and insert it in a selected area on the Template tab. The
different categories of data selected are all different sizes but pasted in
the same starting point (ex. cell B1). If I click on macro "A" I get my list
of items from the OEM material tab. When I click on macro "B" I get my
correct list of items from the OEM material tab HOWEVER, the list is smaller
than macro "A" data, and when macro "B" is ran, data from B pastes onto A
but some of the data from A is still visible.
So, how do I have the macro delete the current macro data before running
(pasting) the next selection of data?

Thanks!
KS


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How to delete previous data from 1 macro before running the next?

Hi,

Insert a command like this at the start of your macro with the range
suitably changed

Columns("B:G").ClearContents

Mike

"KS-Macro" wrote:

Hi!
Hope someone can help. I'm sure this is probably very easy for someone. :-)

I have a workbook and 1 tab is called OEM material with about 1000 items
listed and sorted by categories and another tab called Template.

I have created 11 macros that will select certain data by category from the
OEM material tab and insert it in a selected area on the Template tab. The
different categories of data selected are all different sizes but pasted in
the same starting point (ex. cell B1). If I click on macro "A" I get my list
of items from the OEM material tab. When I click on macro "B" I get my
correct list of items from the OEM material tab HOWEVER, the list is smaller
than macro "A" data, and when macro "B" is ran, data from B pastes onto A
but some of the data from A is still visible.
So, how do I have the macro delete the current macro data before running
(pasting) the next selection of data?

Thanks!
KS


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default How to delete previous data from 1 macro before running the next?

If you are using column B in the Template sheet to store the results of the
macros, then put this snippet at the beginning of macro "B"/

'Sub header and Dim statements here
Dim lstRw As Long
lstRw = Sheets("Template").Cells(Rows.Count, 2).End(xlUp).Row
Sheets("Template").Range("B1:B" & lstRw).ClearContents
'The rest of your code here
End Sub

Change the sheet name if required.


"KS-Macro" wrote in message
...
Hi!
Hope someone can help. I'm sure this is probably very easy for someone.
:-)

I have a workbook and 1 tab is called OEM material with about 1000 items
listed and sorted by categories and another tab called Template.

I have created 11 macros that will select certain data by category from
the
OEM material tab and insert it in a selected area on the Template tab. The
different categories of data selected are all different sizes but pasted
in
the same starting point (ex. cell B1). If I click on macro "A" I get my
list
of items from the OEM material tab. When I click on macro "B" I get my
correct list of items from the OEM material tab HOWEVER, the list is
smaller
than macro "A" data, and when macro "B" is ran, data from B pastes onto A
but some of the data from A is still visible.
So, how do I have the macro delete the current macro data before running
(pasting) the next selection of data?

Thanks!
KS




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to delete previous data from 1 macro before running the ne

WOW! Such an easy solution! Thanks. I feel stupid for asking but I am new at
these.

Thanks so much for your help!!

"Mike H" wrote:

Hi,

Insert a command like this at the start of your macro with the range
suitably changed

Columns("B:G").ClearContents

Mike

"KS-Macro" wrote:

Hi!
Hope someone can help. I'm sure this is probably very easy for someone. :-)

I have a workbook and 1 tab is called OEM material with about 1000 items
listed and sorted by categories and another tab called Template.

I have created 11 macros that will select certain data by category from the
OEM material tab and insert it in a selected area on the Template tab. The
different categories of data selected are all different sizes but pasted in
the same starting point (ex. cell B1). If I click on macro "A" I get my list
of items from the OEM material tab. When I click on macro "B" I get my
correct list of items from the OEM material tab HOWEVER, the list is smaller
than macro "A" data, and when macro "B" is ran, data from B pastes onto A
but some of the data from A is still visible.
So, how do I have the macro delete the current macro data before running
(pasting) the next selection of data?

Thanks!
KS


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How to delete previous data from 1 macro before running the ne

Glad I could help. The learning curve is very steep when you start!!

"KS-Macro" wrote:

WOW! Such an easy solution! Thanks. I feel stupid for asking but I am new at
these.

Thanks so much for your help!!

"Mike H" wrote:

Hi,

Insert a command like this at the start of your macro with the range
suitably changed

Columns("B:G").ClearContents

Mike

"KS-Macro" wrote:

Hi!
Hope someone can help. I'm sure this is probably very easy for someone. :-)

I have a workbook and 1 tab is called OEM material with about 1000 items
listed and sorted by categories and another tab called Template.

I have created 11 macros that will select certain data by category from the
OEM material tab and insert it in a selected area on the Template tab. The
different categories of data selected are all different sizes but pasted in
the same starting point (ex. cell B1). If I click on macro "A" I get my list
of items from the OEM material tab. When I click on macro "B" I get my
correct list of items from the OEM material tab HOWEVER, the list is smaller
than macro "A" data, and when macro "B" is ran, data from B pastes onto A
but some of the data from A is still visible.
So, how do I have the macro delete the current macro data before running
(pasting) the next selection of data?

Thanks!
KS


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
Macro with column delete running very slowly Code Numpty Excel Programming 11 October 2nd 08 03:15 PM
Running Total from previous page Vanna Excel Worksheet Functions 6 March 5th 06 08:32 AM
Worksheet Change code not running when you just delete data in cells. KimberlyC Excel Programming 0 June 23rd 05 01:43 AM
Delete Macro After Running Bill Oertell Excel Programming 5 December 24th 03 03:48 AM
Macro that will autofill a column with data, up to the last row of data in previous c Max Velocity Excel Programming 4 November 27th 03 10:34 AM


All times are GMT +1. The time now is 04:55 PM.

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"