Hi,
Very new to VBA in excel. There are two of us at work trying to sort this.
Using excel 2007
Short background....
The first sheet is called 'Index'. The next sheet is called 'master'
Using a userform it collects 3 pieces of data...a ref number, client name and address.
The code copies the 'Master' sheet and renames it to the ref number (TF) and adds to it the client name (CN) and address (SA).
I can do that no problem.
Private Sub cmdshtadd_Click()
Sheets("MASTER").Select
Sheets("MASTER").Copy Before:=Sheets(3)
ActiveSheet.Name = TFtxtbox
Range("B2") = TFtxtbox
Range("D2") = CNtxtbox
Range("G2") = SAtxtbox
End Sub
Where TF is the ref number, CN is the client name and SA is the site address.
The next task is to copy those 3 pieces if data that are input via the userform into the 'Index' page as well....and then for every subsequent new record/copied sheet to add its ref number(TF), name (CN) and address (SA).
This is what we have come up with...
Private Sub cmdshtadd_Click()
Dim tfData As String
Dim cnData As String
Dim saData As String
Dim IRowNum As Long
Dim FRowNum As Long
Dim GRowNum As Long
'Sheets("INDEX").Select
tfData = TFtxtbox.Text
If Cells(28, 2).Value = "" Then
IRowNum = 28
Else
IRowNum = Sheets("INDEX").UsedRange.Rows.Count + 1
End If
cnData = CNtxtbox.Text
If Cells(28, 4).Value = "" Then
FRowNum = 28
Else
FRowNum = Sheets("INDEX").UsedRange.Rows.Count + 1
End If
saData = SAtxtbox.Text
If Cells(28, 9).Value = "" Then
GRowNum = 28
Else
GRowNum = Sheets("INDEX").UsedRange.Rows.Count + 1
End If
Cells(IRowNum, 2).Value = tfData
Cells(FRowNum, 4).Value = cnData
Cells(GRowNum, 9).Value = saData
Sheets("MASTER").Select
Sheets("MASTER").Copy Before:=Sheets(3)
ActiveSheet.Name = tfData
Range("B2") = TFtxtbox
Range("D2") = CNtxtbox
Range("G2") = SAtxtbox
'ActiveSheet.Move After:=ActiveSheet.Next
TFtxtbox.Text = ""
TFtxtbox.SetFocus
CNtxtbox.Text = ""
SAtxtbox.Text = ""
'TextBox2.SetFocus
'CommandButton1.SetFocus
cmdshtadd.Enabled = False
End Sub
It sort of works but the problem is that the first record data is added to the index sheet at line 28 as the code. However the next record gets entered down at line 814 for example...if i then run the userform again it the next line of data is at 815, then 816 etc....we are lost as to why or how !!!!!
I have attached a de-personalised version of the spreadsheet.
Any comments appreciated.
Bookmarks