Use the majority of an existing working code in new project advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,596
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have the working code in use below "DATABASE CODE" & need to use it again but with a small edit.
The "DATABASE CODE" code is run from a command button on worksheet "DATABASE"
The userform opens & the user enters a customers name in TextBox1
The user then selects the command button which closes the userform, adds the customers name from Textbox1 & places it into cell A6
Inserts new row etc etc then opens another userform.

**************************
This is how i wish to use the majority of the same code.
On my worksheet called QUOTES values are entered in rows where the customers name will always be in column A
The user will select a customer & run the QUOTES CODE supplied below from a command button.
Currently ive got as far as the opening of worksheet DATABASE.

Now basically its entering the customer to the "WORKSHEET DATABASE" from the selected cell on "WORKSHEET QUOTES" without the need to open the userform & use Textbox1 etc
Then all the rest, Insert row etc etc & open the last userform.

WORKSHEET QUOTES CODE
........................................................
Code:
Private Sub SendToDatabase_Click()
Dim answer As Integer
Dim r As Long
If ActiveCell.Column = 1 Then
answer = MsgBox("SEND DETAILS TO DATABASE ? ", vbYesNo + vbInformation, "OPEN DATABASE MESSAGE")
If answer = vbYes Then
ActiveWorkbook.Sheets("DATABASE").Activate

End If
Else
MsgBox "YOU NEED TO SELECT A CUSTOMER IN COLUMN A", vbCritical, "SELECT CUSTOMER MESSAGE"
End If
End Sub


WORKSHEET DATABASE CODE
.............................................................
Code:
Private Sub DatabaseSheetTransferButton_Click()
Rows("6:6").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A6:AC6").Borders.LineStyle = xlContinuous
Range("A6:AC6").Borders.Weight = xlThin
Range("A6:AC6").Interior.ColorIndex = 6
Range("A6:AC6").RowHeight = 25
Range("$Q$6").HorizontalAlignment = xlCenter
Sheets("DATABASE").Range("B6").Select
Range("O6").NumberFormat = "$#,##0.00"

Cancel = 0
If TextBox1.Text = "" Then
    Cancel = 1
    MsgBox "YOU MUST ENTER A CUSTOMERS NAME", vbCritical, "DATABASE USER FORM NAME TRANSFER"
    TextBox1.SetFocus
    
End If

If Cancel = 1 Then
Exit Sub
End If

Dim i As Long
Dim x As Long
Dim ctrl As Control
Dim lastrow As Long
    
With ThisWorkbook.Worksheets("DATABASE")
    .Range("A6").Value = TextBox1.Text

End With

Unload DatabaseUserForm
DatabaseToSheet.Show

End Sub

Once this is done i will look to populate the opened userform from values entered on worhseet "QUOTES"
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
So i have this in place so far but im missing something.

I am able to open the worksheet DATABASE & i see the cell B6 is selected.
The code is missing the part where it inserts a new row & borders etc.

I do the F8 thing & watch the code.
Once i see the cell on worksheet DATABASE A6 selected the code then steps through each line of code below but nothing happens on the sheet & cell A6 is still just selected.

Do see why a new row isnt inserted etc

VBA Code:
Private Sub SendToDatabase_Click()
Dim answer As Integer
Dim r As Long
If ActiveCell.Column = 1 Then
answer = MsgBox("SEND DETAILS TO DATABASE ? ", vbYesNo + vbInformation, "OPEN DATABASE MESSAGE")
If answer = vbYes Then
ActiveWorkbook.Sheets("DATABASE").Activate
Rows("6:6").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A6:AC6").Borders.LineStyle = xlContinuous
Range("A6:AC6").Borders.Weight = xlThin
Range("A6:AC6").Interior.ColorIndex = 6
Range("A6:AC6").RowHeight = 25
Range("$Q$6").HorizontalAlignment = xlCenter
Sheets("DATABASE").Range("B6").Select
Range("O6").NumberFormat = "$#,##0.00"
End If
Else
MsgBox "YOU NEED TO SELECT A CUSTOMER IN COLUMN A", vbCritical, "SELECT CUSTOMER MESSAGE"
End If
Exit Sub

DatabaseToSheet2.Show

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top