+ Reply to Thread
Results 1 to 8 of 8

Need Macro to perform TEXT and SUM function in multiple worksheets

  1. #1
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    Question Need Macro to perform TEXT and SUM function in multiple worksheets

    I have two questions as follows.

    1. What should the VBA code be if I want to use "Input Box("Please enter the date. i.e.MM/DD/YY")" to indicate the date in the formula text instead of putting a date in the cell I2?

    Please Login or Register  to view this content.
    2. If I want to sum a number of rows in a number of worksheets (except the first two ones, number of worksheets varies in different workbooks) and the number of rows varies in each worksheet (it starts with the same cell, let say F1, but ends with different cell in each worksheet), what should the VBA code be? I quoted an example below.

    Worksheet 1
    Column F
    Row 1 10
    Row 2 20
    Row 3 40
    Row 4 30
    Row 5 =sum(F1:F4)

    Worksheet 2
    Column F
    Row 1 10
    Row 2 20
    Row 3 40
    Row 4 30
    Row 5 30
    Row 6 30
    Row 7 =sum(F1:F6)


    Thanks in advance for answering!
    Last edited by alexxgalaxy; 01-12-2013 at 07:59 PM.

  2. #2
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    Re: VBA to perform TEXT and SUM function in multiple worksheets

    I tried to replace the text function with following code. I didn't ran into error but there was nothing came up in the cell C3 either. Could any help?

    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA to perform TEXT and SUM function in multiple worksheets

    Quote Originally Posted by alexxgalaxy View Post
    I tried to replace the text function with following code. I didn't ran into error but there was nothing came up in the cell C3 either. Could any help?

    Please Login or Register  to view this content.
    Try this...
    Please Login or Register  to view this content.

    And this...
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    Re: VBA to perform TEXT and SUM function in multiple worksheets

    Thank you Alpha Frog! They worked wonderful, separately.

    I came up with another problem when I tried to put them together as follows, though. Actually, besides the date, I also did came up with other more codes including adding rows & columns, formatting some cells. I tried to put MyDate's codes before "Next i" and another time after "For i = 3 To sheets.Count" but both didn't work. All it did was that the Inputbox message popped up for every sheets (starting the 3rd one) but at the end except on the 3rd sheet, the value of C3 was empty in the rest of the sheets. I didn't try further with the other codes because of the failed attempt with MyDate's code

    May I know where shall I place these codes so that they would work on every sheets (except the first two)?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    Re: VBA to perform TEXT and SUM function in multiple worksheets

    Okay, I sort of solved part of the problems by putting the following code I searched from the net after the Sum_ColumnF_Rows codes, followed by those add-rows-columns-values-formatting codes. Still, I couldn't make the MyDate codes work on every sheets starting from the 3rd one.


    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    Re: VBA to perform TEXT and SUM function in multiple worksheets

    I tried again and revised MyDate's code as follows. This time, C3 in all the worksheets was filled with the "As at...". I still got the problem that the InputBox popped up over and over again. So, I shall move the code "MyDate = Application.InputBox..." before the code "For i = 3 To sheets.Count"?

    Please Login or Register  to view this content.
    Last edited by alexxgalaxy; 01-12-2013 at 11:33 AM.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Need Macro to perform TEXT and SUM function in multiple worksheets

    It would be better if you simply described what you want to do.

    This will prompt you once for the date and then put that same date and the sum formula for each worksheet after sheet 2. Is that what you want?

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    Re: Need Macro to perform TEXT and SUM function in multiple worksheets

    Thank you so much, AlphaFrog! This works perfectly and is definitely neater.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1