VBA to stop writing to specific sheet based on user selection

Paul15

New Member
Joined
Jun 25, 2020
Messages
44
Office Version
  1. 2019
Platform
  1. Windows
I have a workbook containing 3 sheets. The first two sheets use a input form to write data to each sheet, and across th two sheets in certain circumstances. I have now added a third sheet where data is inputted from the second input form. This works, however I now wish to filter that write, dependant on user selection. On the 2nd user input form there are 3 scenarios a user can select. These filter fields on the form and therefore the data set which is required to be entered and sent to the sheets. Again this works, however I now wish to stop data being sent to one of the sheets if scenario 1 or 3 is selected. Therefore data should only be sent to sheet 3 if scenario 2 is selected. If scenario 1 or 3 is selected (only one can be selected at a time) then data should not be written to sheet 3.

My basic code for naming the spreadsheet columns is. this sends the data from the input sheet fields to the correct columns on the sheets

VBA Code:
RowCount = Worksheets("Sheet1_Log").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet1_Log").Range("A1")

    .Offset(RowCount, 0).Value = Me.Ref.Value
    .Offset(RowCount, 1).Value = Me.Inp1.Value
    .Offset(RowCount, 2).Value = Me.Inc3.Value
    .Offset(RowCount, 3).Value = Me.Tm3.Value
    .Offset(RowCount, 4).Value = Me.ComboBox1.Value
    .Offset(RowCount, 5).Value = Me.FIDiary.Value
    .Offset(RowCount, 12).Value = Me.TextBox2.Value
    .Offset(RowCount, 27).Value = Me.FIComments.Value
    
    
        
End With


RowCount = Worksheets("Sheet2-Log").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet2-Log").Range("A1")

    .Offset(RowCount, 0).Value = Me.Ref.Value
    .Offset(RowCount, 1).Value = Me.Inp1.Value
    .Offset(RowCount, 2).Value = Me.Inc3.Value
    .Offset(RowCount, 3).Value = Me.Tm3.Value
    .Offset(RowCount, 4).Value = Me.ComboBox1.Value

End With

RowCount = Worksheets("Sheet3").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet3").Range("A1")

    .Offset(RowCount, 0).Value = Me.Ref.Value
    .Offset(RowCount, 1).Value = Me.Inp1.Value
    .Offset(RowCount, 2).Value = Me.Inc3.Value
    .Offset(RowCount, 3).Value = Me.Tm3.Value

End With

The code is much longer than this, I have just copied the first few lines

I then have my selection code which filters off (hides) those field I do not wish collect data in on the input forms.

VBA Code:
Private Sub FIFDA_Click()

If FIFDA.Enabled = True Then


If FIDiary.Enabled = True Then FIDiary.Text = "Test - - - - -"
  
Me.FIPort.Visible = False
Me.Label18.Visible = False
Me.FILoc.Visible = False
Me.Label20.Visible = False

End Sub


Private Sub FIINDET_Click()

If FIFDA.Enabled = True Then


'If FIDiary.Enabled = True Then FIDiary.Text = "Test ********"

    
Me.FIWhom.Visible = False
Me.Label17.Visible = False

End Sub

Private Sub FIODA_Click()

If FIFDA.Enabled = True Then


If FIDiary.Enabled = True Then FIDiary.Text = "UK ^^^^^^^^^^"
    
   
    
Me.FIInLand.Visible = False
Me.FIINDET.Visible = False
Me.FIPort.Visible = False

End Sub

So what i am looking for is,

If Sub FIFDA_Click() = True Then

write to Sheets 1 and 2 but not 3

If Sub FIINDET_Click() = True Then

write to sheets 1, 2, 3

If Sub FIODA_Click() = True Then

write to sheets 1 and 2 but not 3

Any help always appreciated - best wishes
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Dear users, after some fiddling I have worked it out. By placing the code for naming the spreadsheet columns; top code, for the specific sheet I am interested in, within the private sub code for the selection where i want the code to write, If Sub FIINDET_Click() = True Then write to sheets 1, 2, 3, it writes on this scenario only and not on others. Cheers all
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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