Page 1 of 2 12 LastLast
Results 1 to 40 of 52

Thread: VB code not updating Excel Sheet 1

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    VB code not updating Excel Sheet 1

    Okay now, my master sheet doesn't seem to be updating but the code seems to work perfect. Sheeet 2 updates, but sheet 1 isn't. Here is my code:

    Option Explicit
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Sub pause()
    Dim pause As Worksheet
    Do
    For Each pause In ThisWorkbook.Worksheets
    pause.Activate
    Application.Wait Now + TimeValue("00:00:15")
    End Sub

    Public Sub Switch()

    Dim ws As Worksheet

    Do
    For Each ws In ThisWorkbook.Worksheets
    ws.Activate
    Application.Wait Now() + TimeValue("00:00:15")
    If GetAsyncKeyState(vbKeyShift) Then Exit Sub
    DoEvents
    Next ws
    Loop

    End Sub

    Private Sub Workbook_Open()
    Application.OnTime Now + TimeValue("00:00:15"), "ThisWorkbook.Switch"
    End Sub
    Rate this post

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB code not updating Excel Sheet 1

    Okay now, my master sheet doesn't seem to be updating but the code seems to work perfect. Sheeet 2 updates, but sheet 1 isn't. Here is my code:
    i do not see anything in your code that changes sheets, so nothing to update
    using pause as both a procedure and a variable is very likely to cause problem, though i do not see that pause is called from anywhere

    i do not really see the point in looping through all the sheets and activating them, but i suppose you have some reason
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: VB code not updating Excel Sheet 1

    I think if we had a better understanding of what you are trying to accomplish it would be easier to offer help.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Basically I have two sheets. This is displayed on TV screen 24/7. The code above cycles through the two sheets and updates one of the fields automatically based on the date. It works perfect except the first sheet isn't updating. Make more sense?

  5. #5
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: VB code not updating Excel Sheet 1

    Is there code behind he the worksheet_activate event for each sheet?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    all this code is in thisworkbook

  7. #7
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: VB code not updating Excel Sheet 1

    I guess I'm trying to understand how it is updated... is there a formula in a cell that gets updated when the date changes or is there other code that executes, etc.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Yes sheet one has cells with formulas that update the cells. Sheet 2 is all text other than the vbcode field.

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Can I see your file?

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Talking Re: VB code not updating Excel Sheet 1

    Quote Originally Posted by koolsid View Post
    Can I see your file?

    Sid
    can I see you!!!
    Ha Ha Ha

  11. #11
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Quote Originally Posted by VBFnewcomer View Post
    can I see you!!!
    Ha Ha Ha


    I am there... I am there

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Attached is the file. The forumlas are based from a software piece that is installed on the clients, so that is how they update. any help is appreciated.
    Attached Files Attached Files

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    You have got the locations mixed up.

    You have pasted the Workbook Open event in the module and the module code in Workbook Area... Try this...

    Sid
    Attached Files Attached Files
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    with the one above the spreadsheet isn't switching anymore and I get an error " cannot run the macro, it maybe not be in this workbook or disabled." Now what?

  15. #15
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Ok do one thing...open the workbook and see where have i place the code... Make those changes in your original file...

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    I just extracted the xls you posted. Not sure what else you mean. I get that macro error.

  17. #17
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Ok Do this...

    Open your original workbook

    Click on Menu ~~~> Tools ~~> Macro ~~> Visual basic Editor and copy the code in the module and paste it in the workbook code area instead of module. similarly copy the code from the Workbook code area and paste it in the Module. Hope that makes sense?

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Quote Originally Posted by koolsid View Post
    Ok Do this...

    Open your original workbook

    Click on Menu ~~~> Tools ~~> Macro ~~> Visual basic Editor and copy the code in the module and paste it in the workbook code area instead of module. similarly copy the code from the Workbook code area and paste it in the Module. Hope that makes sense?

    Sid
    I am running Excel 2010. Also, did that and still get that macro error.

  19. #19
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Put this in the Workbook Open event

    Code:
    Private Sub Workbook_Open()
        Application.OnTime Now + TimeValue("00:00:15"), "Switch"
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Okay. I want to make sure we're on the same page. Here is ThisWorkbook

    Private Sub Workbook_Open()
    Application.OnTime Now + TimeValue("00:00:15"), "ThisWorkbook.Switch"
    End Sub

    and here is module 1:

    Option Explicit
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Sub pause()
    Dim pause As Worksheet
    Do
    For Each pause In ThisWorkbook.Worksheets
    pause.Activate
    Application.Wait Now + TimeValue("00:00:15")
    End Sub

    Public Sub Switch()

    Dim ws As Worksheet

    Do
    For Each ws In ThisWorkbook.Worksheets
    ws.Activate
    Application.Wait Now() + TimeValue("00:00:15")
    If GetAsyncKeyState(vbKeyShift) Then Exit Sub
    DoEvents
    Next ws
    Loop

    End Sub

    This is not working. Cells don't update on master sheet. Now when I click on the excel doc, the goal is for the macro to autorun and obviously have the cells update on both sheets.

  21. #21
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Please re-upload your workbook with the changes that you have done.

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Here you go. Slap me if missed something.
    Attached Files Attached Files

  23. #23
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    SLAP SLAP!



    Ok I have checked it and my guess was right...

    Compare my post 19 and your post 20 once again please. Do you see some difference? Any difference?

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    okay I see what I did. I forgot to change it to "switch". Now it does switch again but no filelds are updating on sheet 1, not even the time.

  25. #25
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Ok. Now the macro is running but where is the code for updating the sheets? Or how is it supposed to update?

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Page 1 (master). is all forumlas. That sheet works perfect if the macro is not running. It updates based on the forumla.

  27. #27
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Is this what you are trying to do?

    Code:
    Public Sub Switch()
        Dim ws As Worksheet
        Do
            For Each ws In ThisWorkbook.Worksheets
                ws.Activate
                Calculate
                Application.Wait Now() + TimeValue("00:00:15")
                If GetAsyncKeyState(vbKeyShift) Then Exit Sub
                DoEvents
            Next ws
        Loop
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    I added that and the forumla still doesn't update until I kill the macro

    Module 1:

    Option Explicit
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Sub pause()
    Dim pause As Worksheet
    Do
    For Each pause In ThisWorkbook.Worksheets
    pause.Activate
    Application.Wait Now + TimeValue("00:00:15")
    End Sub

    Public Sub Switch()

    Dim ws As Worksheet

    Do
    For Each ws In ThisWorkbook.Worksheets
    ws.Activate
    Calculate
    Application.Wait Now() + TimeValue("00:00:15")
    If GetAsyncKeyState(vbKeyShift) Then Exit Sub
    DoEvents
    Next ws
    Loop

    End Sub

  29. #29
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: VB code not updating Excel Sheet 1

    Try

    Code:
    ws.calculate
    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    still not updating, any other ideas guys?
    Last edited by sentinelace; Dec 10th, 2010 at 03:49 PM.

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    bump. Anyone?

  32. #32
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB code not updating Excel Sheet 1

    i made up a workbook for testing, even with a UDF the updating worked correctly (with ws.calculate), so it must have to do with your external data source which we can not test at all

    there was no need to start a new thread to say you did not have a solution in this one
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  33. #33

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    So what now? Is there a way I can simply use the excel with just sheet 1 and have it switch between html and excel?

  34. #34
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB code not updating Excel Sheet 1

    at no point in the past have you mentioned html, you have been talking about 2 worksheets

    the only way for anyone to help you is to have the datasource for testing
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  35. #35

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    I am just trying to figure out a way to make it update. Makes no sense

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    what about completely stopping the macro every so many seconds. Since that seems to have it update when it stops, then loop. That possible?

  37. #37
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB code not updating Excel Sheet 1

    ok, try using application.ontime, to switch sheets, instead of application.wait

    afaik during the wait period nothing can happen in excel

    not tested
    vb Code:
    1. Sub Switch()
    2. If GetAsyncKeyState(vbKeyShift) Then Exit Sub
    3. If ActiveSheet.Index = Sheets.count Then
    4.     nexsht = 1
    5.     Else: nexsht = ActiveSheet.Index + 1
    6. End If
    7. Sheets(nexsht).Activate
    8. Application.OnTime Now + TimeValue("00:00:15"), "Switch"
    9. End Sub
    Last edited by westconn1; Dec 14th, 2010 at 03:27 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  38. #38

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    I get a compile error. Where do I put this code? Do I replace all my existing?

  39. #39
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB code not updating Excel Sheet 1

    just replace your existing switch procedure

    does not look like you are using pause procedure anyway

    I get a compile error
    what error message?
    what code is highlighted?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  40. #40

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Here is what I have for Module 1:

    Code:
    Option Explicit
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Sub pause()
    Dim pause As Worksheet
    Do
    For Each pause In ThisWorkbook.Worksheets
    pause.Activate
    Application.Wait Now + TimeValue("00:00:15")
    End Sub
     
    Public Sub Switch()
     
      Dim ws As Worksheet
     
      Do
        For Each ws In ThisWorkbook.Worksheets
          ws.Activate
          ws.Calculate
          Application.Wait Now() + TimeValue("00:00:15")
          If GetAsyncKeyState(vbKeyShift) Then Exit Sub
          DoEvents
        Next ws
      Loop
     
    End Sub
    This workbook looks like this:

    Code:
    Private Sub Workbook_Open()
    Application.OnTime Now + TimeValue("00:00:15"), "Switch"
    End Sub
    So what am I replacing here?

    I tried:

    Code:
    Option Explicit
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Sub Switch()
    If GetAsyncKeyState(vbKeyShift) Then Exit Sub
    If ActiveSheet.Index = Sheets.Count Then
    nexsht = 1
    Else: nexsht = ActiveSheet.Index + 1
    End If
    Sheets(nexsht).Activate
    Application.OnTime Now + TimeValue("00:00:15"), "Switch"
    End Sub
     
    Public Sub Switch()
     
      Dim ws As Worksheet
     
      Do
        For Each ws In ThisWorkbook.Worksheets
          ws.Activate
          ws.Calculate
          Application.Wait Now() + TimeValue("00:00:15")
          If GetAsyncKeyState(vbKeyShift) Then Exit Sub
          DoEvents
        Next ws
      Loop
     
    End Sub
    Public Sub gets the compile error. Do I need to do anything to thisworkbook? I assume I edited it wrong.
    Last edited by sentinelace; Dec 15th, 2010 at 09:50 AM.

Page 1 of 2 12 LastLast

Posting Permissions

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



Click Here to Expand Forum to Full Width