Consulting

Results 1 to 3 of 3

Thread: VBA code Problem

  1. #1
    VBAX Regular
    Joined
    Jul 2015
    Posts
    66
    Location

    VBA code Problem

    Hi everybody,
    Does anyone know how to generate numbers in a number of sheets. These sheets are generated based on numbers that can be inserted. I am attaching a VBA code file that generates the sheets, but I do not know how to generate numbers in these sheets. For example: if the generated sheets are four sheets, so I want o generated in the first sheet numbers from 1 to 10, in the second sheet I want to generate numbers from 1 to 20, in the third sheet I want to generate numbers from 1 to 30 and t in the fourth sheet I want to generate numbers from 1 to 40. I will be grateful if you help me. Thanks in advance.
    Attached Files Attached Files

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Sub AddSheets3()  
      Dim i As Integer, j As Integer, ii() As Integer
      
      'For i = Application.InputBox("Starting number?") To Application.InputBox("Ending number?")
      For i = 1 To Application.InputBox("number?")
        ReDim ii(1 To i * 10)
        For j = 1 To i * 10
          ii(j) = j
        Next j
        
        Sheets.Add.Name = "ContainerDeparture " & i
        With ActiveSheet
          .Range("A1").Value = "Numbers"
          .Range("A2").Resize(UBound(ii)).Value = WorksheetFunction.Transpose(ii)
        End With
      Next i
    End Sub

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Option Explicit
    Sub AddSheets3_ph()
        Dim NumberOfSheets As Long, SheetNumber As Long, i As Long
    
        NumberOfSheets = Application.InputBox("Number of Sheets, 0 to exit")
        If NumberOfSheets < 1 Then Exit Sub
    
        For SheetNumber = 1 To NumberOfSheets
            Worksheets.Add(, Worksheets(Worksheets.Count)).Name = "ContainerDeparture " & SheetNumber
            ActiveSheet.Cells(1, 1).Value = "Numbers"
            For i = 1 To 10 * SheetNumber
                ActiveSheet.Cells(i + 1, 1).Value = i
            Next I
        Next SheetNumber
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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