Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2005
    Location
    Asia Pacific, Bangkok Metropolis
    Posts
    378
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Beginner Marco (Excel 2003)

    Hi Hans and all

    I have the following marco, Is there a better way to simplifies it? What is the last line Set rg = Nothing? Do I need to put
    also Set rg2 = Nothing.

    Sub InputRange()

    Dim rg As Range
    Dim rg2 As Range
    Set rg = ActiveSheet.Range("A2")
    Set rg2 = ActiveSheet.Range("A3")
    rg.Value = 500
    rg2.Value2 = 5000
    rg.Font.ColorIndex = 3
    rg2.Font.Bold = True
    Set rg = Nothing

    End Sub
    Hope this is helpful

    francis, <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    My Reading

    Pivot Table 101
    Pivot Table
    Array

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Beginner Marco (Excel 2003)

    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17> It's called a macro, not a marco. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    The macro can be simplified to

    Sub InputRange()
    With Range("A2")
    .Value = 500
    .Font.ColorIndex = 3
    End With
    With Range("A3")
    .Value2 = 5000
    .Font.Bold = True
    End With
    End Sub

    In this version, no object variables are used, so you don't have to set anything to Nothing.

    In general, it is good programming practice to set all object variables to Nothing at the end of a Sub or Function. An object variable is the kind of variable that is assigned a value using Set.

  3. #3
    3 Star Lounger
    Join Date
    Nov 2005
    Location
    Asia Pacific, Bangkok Metropolis
    Posts
    378
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Beginner Marco (Excel 2003)

    Hans, As always, thanks you. The codes I wrote look clumsy as compare to yours.
    Hope this is helpful

    francis, <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    My Reading

    Pivot Table 101
    Pivot Table
    Array

Posting Permissions

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