Results 1 to 7 of 7

Add Formula to cell !

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    Add Formula to cell !

    Hi

    In my userform i add data to the sheet as the code below:
     iRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
            If ws.Cells(1, 1) <> "" Then iRow = iRow + 1
            I = Val(ComboBox2.Tag)
            ws.Cells(iRow, 1) = ComboBox3.Value
            ws.Cells(iRow, 6) = TextBox2.Value
            ws.Cells(iRow, 3) = TextBox3.Value
            ws.Cells(iRow, 2) = ComboBox4.Value
            ws.Cells(iRow, 4) = ComboBox2.List(I, 0)
            ws.Cells(iRow, 5) = ComboBox2.List(I, 1)
    Is it possible to add a formula that merge the cell in column A (iROW1) and B(iROW2) to Column G (iROW7)
    something like below ?

    ws.Cells(iRow, 7) = Formula "=A&B"
    All Code
    Private Sub CommandButton1_Click()
        Dim ws As Worksheet, txtb As Control
        Dim aCell As Range, iRow As Integer
    
        If Len(Trim(ComboBox2.Value)) = 0 Then
            MsgBox "Ange Kontonummer"
            ComboBox2.SetFocus
            Exit Sub
        End If
        If Len(Trim(ComboBox3.Value)) = 0 Then
            MsgBox "Ange År"
            ComboBox3.SetFocus
            Exit Sub
        End If
     
       If Len(Trim(ComboBox4.Value)) = 0 Then
            MsgBox "Ange Månad"
            ComboBox4.SetFocus
            Exit Sub
        End If
        
          If Len(Trim(TextBox2.Value)) = 0 Then
            MsgBox "Ange Beskrivning"
            TextBox2.SetFocus
            Exit Sub
        End If
        
      Set ws = Sheets(ComboBox1.Text)
      
        
        If Not aCell Is Nothing Then
            MsgBox "Account Already Exists"
        Else
            iRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
            If ws.Cells(1, 1) <> "" Then iRow = iRow + 1
            I = Val(ComboBox2.Tag)
            ws.Cells(iRow, 1) = ComboBox3.Value
            ws.Cells(iRow, 6) = TextBox2.Value
            ws.Cells(iRow, 3) = TextBox3.Value
            ws.Cells(iRow, 2) = ComboBox4.Value
            ws.Cells(iRow, 4) = ComboBox2.List(I, 0)
            ws.Cells(iRow, 5) = ComboBox2.List(I, 1)
           
        End If
        
        '~~> Clear All textboxes
        For Each txtb In Me.Controls
            If TypeName(txtb) = "TextBox" Then
                txtb.Text = ""
            End If
        Next
        Call ComboBox1_Change
       
        
        
    End Sub
    Best Regards

    Petter
    Last edited by Petter120; 03-02-2012 at 09:57 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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