Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Adding a dymanic formula to a cell using visual basic

Hello,

I have been trying to add a dymanic formula to a cell using visual
basic and I am running into a little difficulty. Any assistance would
be appreciated.

I attempted using the following code. The problem line is marked with
the words "Problem Line" at the end.

Thank you in advance.

--Ian Web

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Phone Numbers")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for Last Name
If Trim(Me.Txt_Last_Name.Value) = "" Then
Me.Txt_Last_Name.SetFocus
MsgBox "Please enter an Employee Last Name"
Exit Sub
End If

'check for First Name
If Trim(Me.Txt_First_Name.Value) = "" Then
Me.Txt_First_Name.SetFocus
MsgBox "Please enter an Employee First Name"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.Txt_Last_Name.Value
ws.Cells(iRow, 2).Value = Me.Txt_First_Name.Value
ws.Cells(iRow, 3).Value = "=CONCATENATE(A"&iRow&","", "",B"&iRow&")"
<-- Problem Line
ws.Cells(iRow, 4).Value = Me.Txt_Phone.Value
ws.Cells(iRow, 5).Value = Me.Txt_Floor.Value
ws.Cells(iRow, 6).Value = Me.Txt_Area.Value

'Sort The Columns by Last Name, First Name

ws.Columns("A:F").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
Key2:=Range("B2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal


'clear the data
Me.Txt_Last_Name.Value = ""
Me.Txt_First_Name = ""
Me.Txt_Phone = ""
Me.Txt_Floor = ""
Me.Txt_Area = ""
Me.Txt_Last_Name.SetFocus

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjust Cell Width in Visual Basic j Excel Discussion (Misc queries) 2 July 5th 06 07:48 PM
Adding a row to worksheet does not update cell references in another. blausen Excel Worksheet Functions 5 February 25th 06 09:14 PM
Match then lookup Tenacity Excel Worksheet Functions 9 December 3rd 05 05:30 AM
adding a formula in a cell but when cell = 0 cell is blank Mike T Excel Worksheet Functions 5 May 31st 05 01:08 AM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM


All times are GMT +1. The time now is 05:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"