+ Reply to Thread
Results 1 to 2 of 2

Incremental code for inputting data

Hybrid View

  1. #1
    Registered User
    Join Date
    07-17-2012
    Location
    Delhi, India
    MS-Off Ver
    Excel 2003
    Posts
    16

    Incremental code for inputting data

    In the given file, when i go to Cover Sht. worksheet,

    and i run a macro Sheet1.Insert, it asks for SIS GROUP REFERENCE "say input a" , and then SIS GROUP NAME "say input b".

    this results in creation of a new worksheet.

    but when i repeat the process it results in removal of previous data "a & b".

    Please suggest how i append data rather than overwriting it.

    Option Explicit
    Const StartSheet = 2 ' Starting Sheet
    Dim SheetNo As Integer
    
    Sub Insert()
    Dim CE As String ' from user
    Dim CEName As String ' from user
    Dim lrow As Integer
    CE = InputBox("Enter SIS GROUP REF", "String Input", "")
    CEName = InputBox("Enter SIS GROUP NAME", "String Input", "")
    Worksheets("Cover Sht.").Range("G10") = CE
    Worksheets("Cover Sht.").Range("H10") = CEName
    Worksheets("Sample").Copy After:=Sheets(3)
    Worksheets("Sample (2)").Select
    Worksheets("Sample (2)").Name = CE
    Worksheets(CE).Range("AQ32") = CE
    Worksheets(CE).Range("AQ33") = CEName
    Worksheets(CE).Range("AS37") = SheetNo
    End Sub
    Attached Files Attached Files
    Last edited by arlu1201; 07-23-2012 at 07:38 AM. Reason: Use code tags in future.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Incremental code for inputting data

    Try this
    Option Explicit
    Const StartSheet = 2 ' Starting Sheet
    Dim SheetNo As Integer
    
    Sub Insert()
    Dim CE As String ' from user
    Dim CEName As String ' from user
    Dim lrow As long
    CE = InputBox("Enter SIS GROUP REF", "String Input", "")
    CEName = InputBox("Enter SIS GROUP NAME", "String Input", "")
    lrow=worksheets("Cover Sht.").range("G" & rows.count).end(xlup).row
    Worksheets("Cover Sht.").Range("G" & lrow+1) = CE
    Worksheets("Cover Sht.").Range("H" & lrow+1) = CEName
    Worksheets("Sample").Copy After:=Sheets(3)
    Worksheets("Sample (2)").Select
    Worksheets("Sample (2)").Name = CE
    Worksheets(CE).Range("AQ32") = CE
    Worksheets(CE).Range("AQ33") = CEName
    Worksheets(CE).Range("AS37") = SheetNo
    End Sub
    Does this work?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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