Mis Aligning Data via submit button

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
771
Office Version
  1. 365
Platform
  1. Windows
I am using the below VB to populate the info filled on my userform to find the line the info was from then fill in the last 4 columns
The code has been working previously but the info is now stored on 1 of 3 sheets in my workbook. "Ashley Longman" This is checked to find the right name. It finds the correct link and then puts it 1 row underneath in the correct columns. How can i re align this correctley?

Rich (BB code):
Dim iRow As Long
Dim ws As Worksheet
    If Me.JEN.Value = "" Then ' Check before submit
        MsgBox "Please Complete is this a justified Enquiry"
    Else
        If Me.AComm.Value = "" Then ' Check before submit
            MsgBox "Please Leave Your Comments"
        Else
            If Me.CBoxAdd.Value = "" Then ' Check before submit
                MsgBox "Please Enter Your Name"
            Else
                'Workbooks.Open Filename:="C:\Users\MAZZA\Documents\Gavin\Car Park\Data.xls" Home
                Workbooks.Open Filename:="\\W2K6082\COMMON\SHARED\Gavin Mazza\Car Park\Data.xls"
            
                If UserForm1.TextBox13 = "Ashley Longman" Then 'Info location
                    ActiveWorkbook.Sheets("Ashley Longman").Activate
                    Unload Me
                    Set ws = Worksheets("Ashley Longman")
                    iRow = ws.Cells(Rows.Count, 11) _
                        .End(xlUp).Offset(1, 0).Row
    'copy the data to the database
                    ws.Cells(iRow, 12).Value = Me.JEN.Value
                    ws.Cells(iRow, 14).Value = Me.AComm.Value
                    ws.Cells(iRow, 15).Value = Me.CBoxAdd.Value
                    ws.Cells(iRow, 13).Value = Me.TextBox12
    'clear the data
                    Me.JEN.Value = ""
                    Me.AComm.Value = ""
                    Me.CBoxAdd.Value = ""
                    Me.TextBox12.Value = ""
                    Me.txtdate.Enabled = True
                    
                    Workbooks("Data.xls").Close True
                    
                End If
            End If
        End If
    End If

Many Thanks:(
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this

Code:
Dim iRow As Long
Dim ws As Worksheet
    If Me.JEN.Value = "" Then ' Check before submit
        MsgBox "Please Complete is this a justified Enquiry"
    Else
        If Me.AComm.Value = "" Then ' Check before submit
            MsgBox "Please Leave Your Comments"
        Else
            If Me.CBoxAdd.Value = "" Then ' Check before submit
                MsgBox "Please Enter Your Name"
            Else
                'Workbooks.Open Filename:="C:\Users\MAZZA\Documents\Gavin\Car Park\Data.xls" Home
                Workbooks.Open Filename:="[URL="file://\\W2K6082\COMMON\SHARED\Gavin"]\\W2K6082\COMMON\SHARED\Gavin[/URL] Mazza\Car Park\Data.xls"
            
                If UserForm1.TextBox13 = "Ashley Longman" Then 'Info location
                    ActiveWorkbook.Sheets("Ashley Longman").Activate
                    Unload Me
                    Set ws = Worksheets("Ashley Longman")
                    iRow = ws.Cells(Rows.Count, 11).End(xlUp).Row
    'copy the data to the database
                    ws.Cells(iRow, 12).Value = Me.JEN.Value
                    ws.Cells(iRow, 14).Value = Me.AComm.Value
                    ws.Cells(iRow, 15).Value = Me.CBoxAdd.Value
                    ws.Cells(iRow, 13).Value = Me.TextBox12
    'clear the data
                    Me.JEN.Value = ""
                    Me.AComm.Value = ""
                    Me.CBoxAdd.Value = ""
                    Me.TextBox12.Value = ""
                    Me.txtdate.Enabled = True
                    
                    Workbooks("Data.xls").Close True
                    
                End If
            End If
        End If
    End If
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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