mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Macro to automatically add rows whenever a certain value is entered

Author Message
Hedros

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 12/17/2009
  • Status: offline
Macro to automatically add rows whenever a certain value is entered Thursday, December 17, 2009 2:27 AM (permalink)
0
Dear experts,
 
I have had some experience with VBscript before but am far from an expert, which is why I would like your help to sort out the following:
 
I am looking for a macro that automaticacly adds 3 rows underneath the cell where the word "cross" is entered. E.g.
 
cell A1     alfa        100
cell A2     beta       200
cell A3     gamma   300
cell A4     Cross     200     -->insert  cell A4    Replace word "Cross" by "Lambda"
                                                        cell A5    delta
                                                        cell A6    epsilon
                                                        cell A7    kappa
Also, all inserted rows need to contain the same formulas as the ones used in cells that are not called "Cross".
 
Hopefully some of you can help.
 
Many thanks in advace for your time and support.
 
KR,
 
H.
#1
    cornerstone137

    • Total Posts : 9
    • Scores: -2
    • Reward points : 0
    • Joined: 3/27/2007
    • Location: South Carolina
    • Status: offline
    Re:Macro to automatically add rows whenever a certain value is entered Monday, December 21, 2009 12:01 AM (permalink)
    0
    Try this:

    Option Explicit
    Private intPreviousRow As Integer, intPreviousColumn As String
    Private strPreviousRow As Integer, strPreviousColumn As String
    Private strPreviousCell As String
    Private blnChangeFlag As Boolean
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim strPreviousCellText As String
     'check to see if the flag has been changed from the ChangeData routine
    If blnChangeFlag = True Then
        strPreviousCellText = Range(strPreviousCell).Text
        If UCase(strPreviousCellText) = "CROSS" Then
            ChangeData
        End If
    End If
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim strRow As String, strColumn As String
    Dim intColumn As Integer
    intPreviousRow = ActiveCell.Row
    blnChangeFlag = True
    intColumn = ActiveCell.Column
    intPreviousColumn = intColumn + 64
    strPreviousColumn = Chr$(Val(intPreviousColumn))
    strPreviousCell = strPreviousColumn & LTrim(Str(intPreviousRow))
    End Sub
    Private Sub ChangeData()
    Dim intDeltaRow As Integer, intEpsilonRow As Integer, intKappaRow As Integer
    Dim strDeltaCell As String, strEpsilonCell As String, strKappaCell As String
    blnChangeFlag = False 'Set to false because Worksheet_Change will be triggered
                            ' when the data is changed below
        intDeltaRow = intPreviousRow + 1
        intEpsilonRow = intPreviousRow + 2
        intKappaRow = intPreviousRow + 3
        strDeltaCell = strPreviousColumn & LTrim(Str(intDeltaRow))
        strEpsilonCell = strPreviousColumn & LTrim(Str(intEpsilonRow))
        strKappaCell = strPreviousColumn & LTrim(Str(intKappaRow))
        Range(strDeltaCell).FormulaR1C1 = "delta"
        Range(strEpsilonCell).FormulaR1C1 = "epsilon"
        Range(strKappaCell).FormulaR1C1 = "kappa"
    blnChangeFlag = True
    End Sub
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.8
      mbt shoes www.wileywilson.com