+ Reply to Thread
Results 1 to 10 of 10

Function exists prematurely

Hybrid View

brain Function exists prematurely 03-30-2006, 01:00 PM
Guest Re: Function exists... 03-30-2006, 01:40 PM
brain There was a problem with one... 03-30-2006, 02:14 PM
Guest Re: Function exists... 03-31-2006, 02:40 AM
Guest Re: Function exists... 03-31-2006, 04:55 AM
Guest Re: Function exists... 03-31-2006, 05:35 AM
Guest Re: Function exists... 03-31-2006, 06:30 AM
Guest Re: Function exists... 03-31-2006, 06:55 AM
brain Nick and Bob, thanks for your... 03-31-2006, 10:09 AM
Guest Re: Function exists... 03-31-2006, 11:20 AM
  1. #1
    Registered User
    Join Date
    03-30-2006
    Posts
    3

    Function exists prematurely

    I'm having a problem with the following function. For some reason, the function returns before the first MsgBox call. It succesfully deletes the column, but it exits right after. Any help?
    Sub main()
    Dim numRates As Integer
    Dim numDates As Integer
    
    Const RateOffset As Integer = 5
    Const DateOffset As Integer = 3
    
    Dim columns As Range
    Dim ratesRange As Range
    
    numRates = Range("IntTimeSeriesRates").Value
    numDates = Range("IntTimeSeriesDates").Value
    
    Set columns = Range(Cells(RateOffset, DateOffset + numDates - 1), Cells(RateOffset + numDates, DateOffset + numDates - 1))
    columns.Delete
    
    MsgBox "Hello1"
    Set columns = Range(Cells(RateOffset, DateOffset), Cells(RateOffset + numRates, DateOffset))
    columns.Insert shift:=xlToRight
    
    MsgBox "Hello2"
    End Sub

  2. #2
    Bob Phillips
    Guest

    Re: Function exists prematurely

    That suggests that the variable columns is getting an invalid value. Step
    through the code and check the value of all the variables in the line that
    sets it.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "brain" <brain.25hsqm_1143738603.653@excelforum-nospam.com> wrote in message
    news:brain.25hsqm_1143738603.653@excelforum-nospam.com...
    >
    > I'm having a problem with the following function. For some reason, the
    > function returns before the first MsgBox call. It succesfully deletes
    > the column, but it exits right after. Any help?
    >
    > Code:
    > --------------------
    >
    > Sub main()
    > Dim numRates As Integer
    > Dim numDates As Integer
    >
    > Const RateOffset As Integer = 5
    > Const DateOffset As Integer = 3
    >
    > Dim columns As Range
    > Dim ratesRange As Range
    >
    > numRates = Range("IntTimeSeriesRates").Value
    > numDates = Range("IntTimeSeriesDates").Value
    >
    > Set columns = Range(Cells(RateOffset, DateOffset + numDates - 1),

    Cells(RateOffset + numDates, DateOffset + numDates - 1))
    > columns.Delete
    >
    > MsgBox "Hello1"
    > Set columns = Range(Cells(RateOffset, DateOffset), Cells(RateOffset +

    numRates, DateOffset))
    > columns.Insert shift:=xlToRight
    >
    > MsgBox "Hello2"
    > End Sub
    >
    > --------------------
    >
    >
    > --
    > brain
    > ------------------------------------------------------------------------
    > brain's Profile:

    http://www.excelforum.com/member.php...o&userid=32991
    > View this thread: http://www.excelforum.com/showthread...hreadid=528185
    >




  3. #3
    Registered User
    Join Date
    03-30-2006
    Posts
    3
    There was a problem with one of the variables, but nothing that was invalid. I fixed it and I'm still getting the problem. I can change the font of columns and it works, but if I try to delete it or clear it, the function exits.

  4. #4
    NickHK
    Guest

    Re: Function exists prematurely

    brain,
    How do think this routine works ?
    Private Sub CountAllcolumnsOnWS()
    MsgBox Columns.Count
    End Sub

    Hint: How many columns do you think Excel is trying to delete ?

    NickHK

    "brain" <brain.25hsqm_1143738603.653@excelforum-nospam.com> wrote in message
    news:brain.25hsqm_1143738603.653@excelforum-nospam.com...
    >
    > I'm having a problem with the following function. For some reason, the
    > function returns before the first MsgBox call. It succesfully deletes
    > the column, but it exits right after. Any help?
    >
    > Code:
    > --------------------
    >
    > Sub main()
    > Dim numRates As Integer
    > Dim numDates As Integer
    >
    > Const RateOffset As Integer = 5
    > Const DateOffset As Integer = 3
    >
    > Dim columns As Range
    > Dim ratesRange As Range
    >
    > numRates = Range("IntTimeSeriesRates").Value
    > numDates = Range("IntTimeSeriesDates").Value
    >
    > Set columns = Range(Cells(RateOffset, DateOffset + numDates - 1),

    Cells(RateOffset + numDates, DateOffset + numDates - 1))
    > columns.Delete
    >
    > MsgBox "Hello1"
    > Set columns = Range(Cells(RateOffset, DateOffset), Cells(RateOffset +

    numRates, DateOffset))
    > columns.Insert shift:=xlToRight
    >
    > MsgBox "Hello2"
    > End Sub
    >
    > --------------------
    >
    >
    > --
    > brain
    > ------------------------------------------------------------------------
    > brain's Profile:

    http://www.excelforum.com/member.php...o&userid=32991
    > View this thread: http://www.excelforum.com/showthread...hreadid=528185
    >




  5. #5
    Bob Phillips
    Guest

    Re: Function exists prematurely

    I don't think that is it, at least it is not in my testing. The code defines
    a variable called columns. Now that may not be a practice that you or I
    would endorse, but it does seem to 'work' as he thinks. It certainly
    wouldn't hurt though if he changed the name and tried again.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "NickHK" <TungCheWah@Invalid.com> wrote in message
    news:ebwAQ2IVGHA.1728@TK2MSFTNGP11.phx.gbl...
    > brain,
    > How do think this routine works ?
    > Private Sub CountAllcolumnsOnWS()
    > MsgBox Columns.Count
    > End Sub
    >
    > Hint: How many columns do you think Excel is trying to delete ?
    >
    > NickHK
    >
    > "brain" <brain.25hsqm_1143738603.653@excelforum-nospam.com> wrote in

    message
    > news:brain.25hsqm_1143738603.653@excelforum-nospam.com...
    > >
    > > I'm having a problem with the following function. For some reason, the
    > > function returns before the first MsgBox call. It succesfully deletes
    > > the column, but it exits right after. Any help?
    > >
    > > Code:
    > > --------------------
    > >
    > > Sub main()
    > > Dim numRates As Integer
    > > Dim numDates As Integer
    > >
    > > Const RateOffset As Integer = 5
    > > Const DateOffset As Integer = 3
    > >
    > > Dim columns As Range
    > > Dim ratesRange As Range
    > >
    > > numRates = Range("IntTimeSeriesRates").Value
    > > numDates = Range("IntTimeSeriesDates").Value
    > >
    > > Set columns = Range(Cells(RateOffset, DateOffset + numDates - 1),

    > Cells(RateOffset + numDates, DateOffset + numDates - 1))
    > > columns.Delete
    > >
    > > MsgBox "Hello1"
    > > Set columns = Range(Cells(RateOffset, DateOffset), Cells(RateOffset +

    > numRates, DateOffset))
    > > columns.Insert shift:=xlToRight
    > >
    > > MsgBox "Hello2"
    > > End Sub
    > >
    > > --------------------
    > >
    > >
    > > --
    > > brain
    > > ------------------------------------------------------------------------
    > > brain's Profile:

    > http://www.excelforum.com/member.php...o&userid=32991
    > > View this thread:

    http://www.excelforum.com/showthread...hreadid=528185
    > >

    >
    >




  6. #6
    NickHK
    Guest

    Re: Function exists prematurely

    Bob,
    Yes, it works, surprisingly I think.
    So I guess it's your suggetsion of the an invalid value for columns.

    NickHK

    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:%23BOS$$JVGHA.5148@TK2MSFTNGP12.phx.gbl...
    > I don't think that is it, at least it is not in my testing. The code

    defines
    > a variable called columns. Now that may not be a practice that you or I
    > would endorse, but it does seem to 'work' as he thinks. It certainly
    > wouldn't hurt though if he changed the name and tried again.
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "NickHK" <TungCheWah@Invalid.com> wrote in message
    > news:ebwAQ2IVGHA.1728@TK2MSFTNGP11.phx.gbl...
    > > brain,
    > > How do think this routine works ?
    > > Private Sub CountAllcolumnsOnWS()
    > > MsgBox Columns.Count
    > > End Sub
    > >
    > > Hint: How many columns do you think Excel is trying to delete ?
    > >
    > > NickHK
    > >
    > > "brain" <brain.25hsqm_1143738603.653@excelforum-nospam.com> wrote in

    > message
    > > news:brain.25hsqm_1143738603.653@excelforum-nospam.com...
    > > >
    > > > I'm having a problem with the following function. For some reason,

    the
    > > > function returns before the first MsgBox call. It succesfully deletes
    > > > the column, but it exits right after. Any help?
    > > >
    > > > Code:
    > > > --------------------
    > > >
    > > > Sub main()
    > > > Dim numRates As Integer
    > > > Dim numDates As Integer
    > > >
    > > > Const RateOffset As Integer = 5
    > > > Const DateOffset As Integer = 3
    > > >
    > > > Dim columns As Range
    > > > Dim ratesRange As Range
    > > >
    > > > numRates = Range("IntTimeSeriesRates").Value
    > > > numDates = Range("IntTimeSeriesDates").Value
    > > >
    > > > Set columns = Range(Cells(RateOffset, DateOffset + numDates - 1),

    > > Cells(RateOffset + numDates, DateOffset + numDates - 1))
    > > > columns.Delete
    > > >
    > > > MsgBox "Hello1"
    > > > Set columns = Range(Cells(RateOffset, DateOffset), Cells(RateOffset

    +
    > > numRates, DateOffset))
    > > > columns.Insert shift:=xlToRight
    > > >
    > > > MsgBox "Hello2"
    > > > End Sub
    > > >
    > > > --------------------
    > > >
    > > >
    > > > --
    > > > brain

    > >

    > ------------------------------------------------------------------------
    > > > brain's Profile:

    > > http://www.excelforum.com/member.php...o&userid=32991
    > > > View this thread:

    > http://www.excelforum.com/showthread...hreadid=528185
    > > >

    > >
    > >

    >
    >




  7. #7
    Bob Phillips
    Guest

    Re: Function exists prematurely

    Hi Nick,

    "NickHK" <TungCheWah@Invalid.com> wrote in message
    news:uPeAbWKVGHA.1304@tk2msftngp13.phx.gbl...

    > Yes, it works, surprisingly I think.


    It surprised me, my first thought was that that was the problem.



  8. #8
    NickHK
    Guest

    Re: Function exists prematurely

    Bob,
    Another indication I should test what I write before posting.

    NickHK

    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:ulnhd1KVGHA.5364@tk2msftngp13.phx.gbl...
    > Hi Nick,
    >
    > "NickHK" <TungCheWah@Invalid.com> wrote in message
    > news:uPeAbWKVGHA.1304@tk2msftngp13.phx.gbl...
    >
    > > Yes, it works, surprisingly I think.

    >
    > It surprised me, my first thought was that that was the problem.
    >
    >




  9. #9
    Registered User
    Join Date
    03-30-2006
    Posts
    3
    Nick and Bob, thanks for your time and comments.

    Looking over the comments that you have both made it occurs to me that columns is a bad variable name as it is used for other things as well. I will make a very simple example with a different variable name and check if it works.

    In my spreadsheet, I have a row of dates. Under each date, is a column of data. What I want to do is:
    1) Delete the right most column from the range
    2) Shift all of the columns over by one
    3) Insert a new date on the left side


    [edit] changing columns to bcolumns (I'm not very creative) solved the problem. Thanks for the help! [/edit]

    Quote Originally Posted by Bob Phillips
    I don't think that is it, at least it is not in my testing. The code defines
    a variable called columns. Now that may not be a practice that you or I
    would endorse, but it does seem to 'work' as he thinks. It certainly
    wouldn't hurt though if he changed the name and tried again.
    Last edited by brain; 03-31-2006 at 10:23 AM.

  10. #10
    Bob Phillips
    Guest

    Re: Function exists prematurely

    That makes a lot of sense. Try it and post back if you still have problems.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "brain" <brain.25jf2n_1143814204.9334@excelforum-nospam.com> wrote in
    message news:brain.25jf2n_1143814204.9334@excelforum-nospam.com...
    >
    > Nick and Bob, thanks for your time and comments.
    >
    > Looking over the comments that you have both made it occurs to me that
    > columns is a bad variable name as it is used for other things as well.
    > I will make a very simple example with a different variable name and
    > check if it works.
    >
    > In my spreadsheet, I have a row of dates. Under each date, is a column
    > of data. What I want to do is:
    > 1) Delete the right most column from the range
    > 2) Shift all of the columns over by one
    > 3) Insert a new date on the left side
    >
    > Bob Phillips Wrote:
    > > I don't think that is it, at least it is not in my testing. The code
    > > defines
    > > a variable called columns. Now that may not be a practice that you or
    > > I
    > > would endorse, but it does seem to 'work' as he thinks. It certainly
    > > wouldn't hurt though if he changed the name and tried again.
    > >

    >
    >
    > --
    > brain
    > ------------------------------------------------------------------------
    > brain's Profile:

    http://www.excelforum.com/member.php...o&userid=32991
    > View this thread: http://www.excelforum.com/showthread...hreadid=528185
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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