vba to copy/paste using user input for index/match variable location

himperson1

New Member
Joined
Jun 23, 2016
Messages
33
im trying to create some code which will request input from the user for the day and shift (i have this much done). then copy data from another page and paste it in the appropriate variable location based on those inputs sent through an index/match function.

Ex: If user inputs 2 for day and 1 for shift, data will be copied and pasted in e3, e4, e5

thanks in advance

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Day[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Shift[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Prod1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Prod2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Prod3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

3DqX4

3DqX4


Code:
    Dim myDay As Variant
    Dim myShift As Variant
    myDay = InputBox("Enter day of the month")
    myShift = InputBox("Enter your shift")


    [I]what goes here?[/I] = Application.WorksheetFunction.Index(Sheets("Trend").Range("B1:CP1"), _
        Application.WorksheetFunction.Match(1, _
        (Sheets("Trend").Range("B1:CP1") = myDay) * (Sheets("Trend").Range("B2:CP2") = myShift), 0), 1)


    Worksheets("Inventory").Range("B12").Copy Worksheets("Trend").Range("[I]location based on index/match[/I]")
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Running into run-time error 13 Type mismatch when it gets to the index function. not sure what is not matching.

currently set as
Trend = Application.WorksheetFunction...
 
Upvote 0
realized i didnt need the index function and will just use match to find which number column (+1) to start putting data in. previous mismatch error is due to however my code is messed up:

Name = Application.WorksheetFunction.Match(1, ((Sheets("Trend").Range("b1:cp1") = myDay) * (Sheets("Trend").Range("b2:cp2") = myShift)), 0)
 
Upvote 0

Forum statistics

Threads
1,223,628
Messages
6,173,426
Members
452,515
Latest member
Alicedonald9

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