Submit button: How to make the destination of submitted data conditional

Morten Lahrmann

New Member
Joined
Jan 25, 2011
Messages
3
Hey all

Im working on a sheet to keep track of a procentage of defects at my job. Here I've created a Submit-button which move three pieces of information "Batchnumber, Precentage, and Product" to another sheet in the same workbook. However, we have two categories of products and I would like to for the submit-macro to place the information moved differently depending on the category.

I would thinking some sort of IF-statement along the lines of "IF the product is PX1, PX2, PX3 move to "B", "C", "D" ELSE move to "F", "G", "H"", but dont know exactly how to include it in the macro code below.

Anyone have any experiences with something similar?

BR
Morten, Denmark

Code:
Sub Rectangle2_Click()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim r1 As Range, r2 As Range
Dim v1 As Variant, v2 As Variant
Set sh1 = Worksheets("Fyldefejl")
Set sh2 = Worksheets("Data")
v1 = Array("E27", "F27", "G27")
v2 = Array("B", "C", "D")
rw = sh2.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).Row
For i = LBound(v1) To UBound(v1)
 Set r1 = sh1.Range(v1(i))
 Set r2 = sh2.Cells(rw, v2(i))
 r1.Copy r2
 r1.ClearContents
Next i
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Welcome to MrExcel.

Try:

Code:
Sub Rectangle2_Click()
    Dim sh1 As Worksheet, sh2 As Worksheet
    Dim rw As Long
    Dim r1 As Range
    Set sh1 = Worksheets("Fyldefejl")
    Set sh2 = Worksheets("Data")
    Set r1 = sh1.Range("E27:G27")
    Select Case sh1.Range("G27").Value
        Case "PX1", "PX2", "PX3"
            rw = sh2.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).Row
            r1.Copy sh2.Range("B" & rw)
        Case Else
            rw = sh2.Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Row
            r1.Copy sh2.Range("F" & rw)
 
    End Select
    r1.ClearContents
End Sub

I removed the unnecessary arrays and loop.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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