CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    218

    help with excel macro

    Code:
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim x
    For x = 1 To 1000
    If Cells(1, 1) <> "" Then
    Cells(2, 1) = "hi"
    End If
    If Cells(2, 2) <> "" Then
    Cells(3, 2) = "hello"
    End If
    End Sub
    When I run this code, the cpu become busy, what happen? thank you.
    Last edited by lwong; April 20th, 2006 at 11:55 PM.

  2. #2
    Join Date
    Apr 2006
    Posts
    15

    Re: help with excel macro

    You can record a macro in Excel and then you can look at the VB code that was generated.

  3. #3
    Join Date
    Feb 2004
    Posts
    218

    Re: help with excel macro

    I know, but what event can do that? when cell A change value, cell B also immediately changed value

  4. #4
    Join Date
    Apr 2006
    Posts
    11

    Re: help with excel macro

    Hi
    What happen is, every time time you check cells(1,1).value you set cells(2,1).value to "HI", which will fire the Workbook_SheetChange event and then it will run sub again and never stop.

    Cheers Karsten

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

Featured