Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
I posted last night. I don't know where it went. it's was a good post.
I will shorten it. 1.) I need to program a macro to clear a certian set or group of fields everyday? 2.) I have it already programed on another sheet, but I can't find it to copy it, change the fields to match my new sheet's fields. 3.) Can you have your macro not only clear fields but also add certian numbers together. ( for instance, I sold four widgets today. That number is in the f15 cell. I trying to keep track of how many widgets I sold all month which is in f20 cell, so at the end of the day, when I clear my daily numbers, I want the four to add to the total for the month and have my sheet keep track. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
Here is a typical "clear" example:
Sub clear_it() Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub The example is three disjoint areas -- Gary''s Student - gsnu200767 "Chris" wrote: I posted last night. I don't know where it went. it's was a good post. I will shorten it. 1.) I need to program a macro to clear a certian set or group of fields everyday? 2.) I have it already programed on another sheet, but I can't find it to copy it, change the fields to match my new sheet's fields. 3.) Can you have your macro not only clear fields but also add certian numbers together. ( for instance, I sold four widgets today. That number is in the f15 cell. I trying to keep track of how many widgets I sold all month which is in f20 cell, so at the end of the day, when I clear my daily numbers, I want the four to add to the total for the month and have my sheet keep track. |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
The code you'd want ahead of the clear operation to add the daily widgit
sales in F15 on a sheet into F20 on that, or another sheet would be similar to this (your worksheet names will be different) Worksheets("Rollup Totals").Range("F20") = _ Worksheets("Rollup Totals").Range("F20") + _ Worksheets("Last Daily Sheet").Range("F15") If you know you'll always be on the "Last Daily Sheet" (the one to be cleared) when the code is run it could read as: Worksheets("Rollup Totals").Range("F20") = _ Worksheets("Rollup Totals").Range("F20") + _ ActiveSheet.Range("F15") And finally, if both F15 and F20 are on the same sheet, then it can be changed to: ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Hope that helps some with the other part of the problem. "Gary''s Student" wrote: Here is a typical "clear" example: Sub clear_it() Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub The example is three disjoint areas -- Gary''s Student - gsnu200767 "Chris" wrote: I posted last night. I don't know where it went. it's was a good post. I will shorten it. 1.) I need to program a macro to clear a certian set or group of fields everyday? 2.) I have it already programed on another sheet, but I can't find it to copy it, change the fields to match my new sheet's fields. 3.) Can you have your macro not only clear fields but also add certian numbers together. ( for instance, I sold four widgets today. That number is in the f15 cell. I trying to keep track of how many widgets I sold all month which is in f20 cell, so at the end of the day, when I clear my daily numbers, I want the four to add to the total for the month and have my sheet keep track. |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
would the macro then be all in the same command.
like... ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Sub clear_it() Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub or would i have to put it in the sub command line? "JLatham" wrote: The code you'd want ahead of the clear operation to add the daily widgit sales in F15 on a sheet into F20 on that, or another sheet would be similar to this (your worksheet names will be different) Worksheets("Rollup Totals").Range("F20") = _ Worksheets("Rollup Totals").Range("F20") + _ Worksheets("Last Daily Sheet").Range("F15") If you know you'll always be on the "Last Daily Sheet" (the one to be cleared) when the code is run it could read as: Worksheets("Rollup Totals").Range("F20") = _ Worksheets("Rollup Totals").Range("F20") + _ ActiveSheet.Range("F15") And finally, if both F15 and F20 are on the same sheet, then it can be changed to: ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Hope that helps some with the other part of the problem. "Gary''s Student" wrote: Here is a typical "clear" example: Sub clear_it() Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub The example is three disjoint areas -- Gary''s Student - gsnu200767 "Chris" wrote: I posted last night. I don't know where it went. it's was a good post. I will shorten it. 1.) I need to program a macro to clear a certian set or group of fields everyday? 2.) I have it already programed on another sheet, but I can't find it to copy it, change the fields to match my new sheet's fields. 3.) Can you have your macro not only clear fields but also add certian numbers together. ( for instance, I sold four widgets today. That number is in the f15 cell. I trying to keep track of how many widgets I sold all month which is in f20 cell, so at the end of the day, when I clear my daily numbers, I want the four to add to the total for the month and have my sheet keep track. |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
Yes, I think. NOT like you showed, my added code would be inside of the Sub
.... End Sub lines, but above his Set r= statement. Like this: Sub clear_it() ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub Or whichever of the other variations of my command you decide works best for you. Also, you should know that the " _" (space followed by underscore) is a way of telling VB to continue the command on the next line. We use that quite a bit in these forums to keep long lines of code from being broken up by the system here. So writing it that way is exactly the same, functionally, as writing it all on one line (which may get broken up here) as: ActiveSheet.Range("F20") = ActiveSheet.Range("F20") + ActiveSheet.Range("F15") Let's revisit the routine and see what it does: Sub clear_it() -- tells the VB engine that this is the beginning of a section of code we want to be able to refer to as 'clear_it'. ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") -- says take the value in cell F20 on the currently selected worksheet and replace that value with the result of adding that value to the value in cell F15 on the same sheet. We need to do that before the r.Clear statement so that we use F15 before its contents get wiped clean. Set r = Range("A1:A4, D2, F10:F15") -- says create a variable named r and and make it refer to the cells specified in the Range() statement on the current/active worksheet. After this anything we do to 'r' is the same as doing it to the individual cells it refers to. r.Clear -- says clear everything in the cells that 'r' refers to. End Sub Note that there are several variations of the .Clear operation (called a 'method'), as: ..ClearContents will ONLY clear the value or formula in the cell. ..ClearFormat would clear any formatting (cell shading, font attributes, borders, etc) of the cell, leaving the value of the cell untouched. Hope this helps some. "Chris" wrote: would the macro then be all in the same command. like... ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Sub clear_it() Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub or would i have to put it in the sub command line? "JLatham" wrote: The code you'd want ahead of the clear operation to add the daily widgit sales in F15 on a sheet into F20 on that, or another sheet would be similar to this (your worksheet names will be different) Worksheets("Rollup Totals").Range("F20") = _ Worksheets("Rollup Totals").Range("F20") + _ Worksheets("Last Daily Sheet").Range("F15") If you know you'll always be on the "Last Daily Sheet" (the one to be cleared) when the code is run it could read as: Worksheets("Rollup Totals").Range("F20") = _ Worksheets("Rollup Totals").Range("F20") + _ ActiveSheet.Range("F15") And finally, if both F15 and F20 are on the same sheet, then it can be changed to: ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Hope that helps some with the other part of the problem. "Gary''s Student" wrote: Here is a typical "clear" example: Sub clear_it() Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub The example is three disjoint areas -- Gary''s Student - gsnu200767 "Chris" wrote: I posted last night. I don't know where it went. it's was a good post. I will shorten it. 1.) I need to program a macro to clear a certian set or group of fields everyday? 2.) I have it already programed on another sheet, but I can't find it to copy it, change the fields to match my new sheet's fields. 3.) Can you have your macro not only clear fields but also add certian numbers together. ( for instance, I sold four widgets today. That number is in the f15 cell. I trying to keep track of how many widgets I sold all month which is in f20 cell, so at the end of the day, when I clear my daily numbers, I want the four to add to the total for the month and have my sheet keep track. |
#6
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
you are so awesome.
"JLatham" wrote: Yes, I think. NOT like you showed, my added code would be inside of the Sub ... End Sub lines, but above his Set r= statement. Like this: Sub clear_it() ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub Or whichever of the other variations of my command you decide works best for you. Also, you should know that the " _" (space followed by underscore) is a way of telling VB to continue the command on the next line. We use that quite a bit in these forums to keep long lines of code from being broken up by the system here. So writing it that way is exactly the same, functionally, as writing it all on one line (which may get broken up here) as: ActiveSheet.Range("F20") = ActiveSheet.Range("F20") + ActiveSheet.Range("F15") Let's revisit the routine and see what it does: Sub clear_it() -- tells the VB engine that this is the beginning of a section of code we want to be able to refer to as 'clear_it'. ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") -- says take the value in cell F20 on the currently selected worksheet and replace that value with the result of adding that value to the value in cell F15 on the same sheet. We need to do that before the r.Clear statement so that we use F15 before its contents get wiped clean. Set r = Range("A1:A4, D2, F10:F15") -- says create a variable named r and and make it refer to the cells specified in the Range() statement on the current/active worksheet. After this anything we do to 'r' is the same as doing it to the individual cells it refers to. r.Clear -- says clear everything in the cells that 'r' refers to. End Sub Note that there are several variations of the .Clear operation (called a 'method'), as: .ClearContents will ONLY clear the value or formula in the cell. .ClearFormat would clear any formatting (cell shading, font attributes, borders, etc) of the cell, leaving the value of the cell untouched. Hope this helps some. "Chris" wrote: would the macro then be all in the same command. like... ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Sub clear_it() Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub or would i have to put it in the sub command line? "JLatham" wrote: The code you'd want ahead of the clear operation to add the daily widgit sales in F15 on a sheet into F20 on that, or another sheet would be similar to this (your worksheet names will be different) Worksheets("Rollup Totals").Range("F20") = _ Worksheets("Rollup Totals").Range("F20") + _ Worksheets("Last Daily Sheet").Range("F15") If you know you'll always be on the "Last Daily Sheet" (the one to be cleared) when the code is run it could read as: Worksheets("Rollup Totals").Range("F20") = _ Worksheets("Rollup Totals").Range("F20") + _ ActiveSheet.Range("F15") And finally, if both F15 and F20 are on the same sheet, then it can be changed to: ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15") Hope that helps some with the other part of the problem. "Gary''s Student" wrote: Here is a typical "clear" example: Sub clear_it() Set r = Range("A1:A4, D2, F10:F15") r.Clear End Sub The example is three disjoint areas -- Gary''s Student - gsnu200767 "Chris" wrote: I posted last night. I don't know where it went. it's was a good post. I will shorten it. 1.) I need to program a macro to clear a certian set or group of fields everyday? 2.) I have it already programed on another sheet, but I can't find it to copy it, change the fields to match my new sheet's fields. 3.) Can you have your macro not only clear fields but also add certian numbers together. ( for instance, I sold four widgets today. That number is in the f15 cell. I trying to keep track of how many widgets I sold all month which is in f20 cell, so at the end of the day, when I clear my daily numbers, I want the four to add to the total for the month and have my sheet keep track. |
#7
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
I got this error message ..method 'range' of object'_Global' but... reading your message again it should say Sub clear_it() ActiveSheet.Range("n16") = _ ActiveSheet.Range("n16") + _ ActiveSheet.Range("c16") ActiveSheet.Range("n17") = _ ActiveSheet.Range("n17") + _ ActiveSheet.Range("c17") ActiveSheet.Range("n18") = _ ActiveSheet.Range("n18") + _ ActiveSheet.Range("c18") ActiveSheet.Range("n19") = _ ActiveSheet.Range("n19") + _ ActiveSheet.Range("c19") ActiveSheet.Range("n20") = _ ActiveSheet.Range("n20") + _ ActiveSheet.Range("c20") ActiveSheet.Range("n21") = _ ActiveSheet.Range("n21") + _ ActiveSheet.Range("c21") ActiveSheet.Range("n22") = _ ActiveSheet.Range("n22") + _ ActiveSheet.Range("c22") ActiveSheet.Range("n23") = _ ActiveSheet.Range("n23") + _ ActiveSheet.Range("c23") ActiveSheet.Range("n24") = _ ActiveSheet.Range("n24") + _ ActiveSheet.Range("c24") ActiveSheet.Range("n25") = _ ActiveSheet.Range("n25") + _ ActiveSheet.Range("c25") ActiveSheet.Range("n26") = _ ActiveSheet.Range("n26") + _ ActiveSheet.Range("c26") ActiveSheet.Range("n27") = _ ActiveSheet.Range("n27") + _ ActiveSheet.Range("c27") ActiveSheet.Range("n28") = _ ActiveSheet.Range("n28") + _ ActiveSheet.Range("c28") ActiveSheet.Range("n29") = _ ActiveSheet.Range("n29") + _ ActiveSheet.Range("c29") ActiveSheet.Range("n30") = _ ActiveSheet.Range("n30") + _ ActiveSheet.Range("c30") Set r = Range("f15:k16, f20:k22, f25:k28, f31:k33, b34:d35, c16:c30, 034") r.ClearContents End Sub ? by the way.. the adding part works... YAY!!!!! thanks again. |
#8
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
Make sure you use o34 (oh-34), not 034 (zero-34).
Chris wrote: I got this error message ..method 'range' of object'_Global' but... reading your message again it should say Sub clear_it() ActiveSheet.Range("n16") = _ ActiveSheet.Range("n16") + _ ActiveSheet.Range("c16") ActiveSheet.Range("n17") = _ ActiveSheet.Range("n17") + _ ActiveSheet.Range("c17") ActiveSheet.Range("n18") = _ ActiveSheet.Range("n18") + _ ActiveSheet.Range("c18") ActiveSheet.Range("n19") = _ ActiveSheet.Range("n19") + _ ActiveSheet.Range("c19") ActiveSheet.Range("n20") = _ ActiveSheet.Range("n20") + _ ActiveSheet.Range("c20") ActiveSheet.Range("n21") = _ ActiveSheet.Range("n21") + _ ActiveSheet.Range("c21") ActiveSheet.Range("n22") = _ ActiveSheet.Range("n22") + _ ActiveSheet.Range("c22") ActiveSheet.Range("n23") = _ ActiveSheet.Range("n23") + _ ActiveSheet.Range("c23") ActiveSheet.Range("n24") = _ ActiveSheet.Range("n24") + _ ActiveSheet.Range("c24") ActiveSheet.Range("n25") = _ ActiveSheet.Range("n25") + _ ActiveSheet.Range("c25") ActiveSheet.Range("n26") = _ ActiveSheet.Range("n26") + _ ActiveSheet.Range("c26") ActiveSheet.Range("n27") = _ ActiveSheet.Range("n27") + _ ActiveSheet.Range("c27") ActiveSheet.Range("n28") = _ ActiveSheet.Range("n28") + _ ActiveSheet.Range("c28") ActiveSheet.Range("n29") = _ ActiveSheet.Range("n29") + _ ActiveSheet.Range("c29") ActiveSheet.Range("n30") = _ ActiveSheet.Range("n30") + _ ActiveSheet.Range("c30") Set r = Range("f15:k16, f20:k22, f25:k28, f31:k33, b34:d35, c16:c30, 034") r.ClearContents End Sub ? by the way.. the adding part works... YAY!!!!! thanks again. -- Dave Peterson |
#9
Posted to microsoft.public.excel.misc
|
|||
|
|||
Macros in excel
so ...
if I wanted for the person in the morning to hit one button and have all the sheets do this action ( keep in mind, the totals would only be per worksheet ) I have a master sheet that keep track of the total totals but I want each sheet to build a monthly total on each sheet... for instance. in the morning. on the master sheet there is a macro that runs that on each of the 8 worksheets repeats this action on all the relevant cells. "ActiveSheet.Range("F20") = _ ActiveSheet.Range("F20") + _ ActiveSheet.Range("F15")" so it would be on each eight worksheet would do this ... but fromone button on the master sheet and nothing would rollup to this master sheet. Or.. ? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macros warning always shows up, even if all macros removed | Excel Discussion (Misc queries) | |||
Macros - copying macros from one computer to another | Excel Discussion (Misc queries) | |||
Macros in Excel 12 | Excel Discussion (Misc queries) | |||
Training: More on how to use macros in Excel: Recording Macros | Excel Worksheet Functions | |||
Excel Macros | Excel Discussion (Misc queries) |