code for clicking a cell in a table that goes to a new sheet and pulls up data about the selected cell from the same row.

Sonican

New Member
Joined
Jun 20, 2016
Messages
13
So basically I have a spreadsheet that is imported from a access database. it has 13 columns and a few thousand rows, but the exact number of rows will vary based on the referenced time frame from a database. in the first column is an identification number, and in the following columns is a bunch of data about that Id number. I need to be able to double click the ID number and have it go to sheet 2 in the excel document and pull up 3 of the statistics from that ID number as well as the id number its self. also, when i click a second ID number, i need the same data to be displayed below the first ID number.

Example data

Lets say I click ID numbers 0003 and 0015

Sheet 1
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]ID number (pull up in sheet 2)[/TD]
[TD]stat 1 (Pull up in sheet 2)[/TD]
[TD]stat 2 (pull up in sheet 2)[/TD]
[TD]stat 3 (pull up in sheet 2)[/TD]
[TD]stat 4 [/TD]
[TD]stat 5[/TD]
[TD]stat 6[/TD]
[TD]stat 7[/TD]
[TD]stat 8[/TD]
[TD]stat 9[/TD]
[TD]stat 10[/TD]
[TD]stat 11[/TD]
[TD]stat 12[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]0001
[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]8[/TD]
[TD]4[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]1[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]0002[/TD]
[TD]6[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]5[/TD]
[TD]4[/TD]
[TD]4[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]>>[/TD]
[TD]0003[/TD]
[TD]5[/TD]
[TD]4[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]2[/TD]
[TD]8[/TD]
[TD]4[/TD]
[TD]9[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]4[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][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I will be honest I am lost when it comes to Visual Basic. any help would be greatly appreciated.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hey,

you can try this:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim LastRow as Long
If Target.Column <> 1 Then Exit Sub
LastRow = Worksheets("[COLOR=#ff0000]Sheet 2[/COLOR]").Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
Cells(Target.Row, 1).Resize(1, 4).Copy _
Destination:=Worksheets("[COLOR=#ff0000]Sheet 2[/COLOR]").Cells(LastRow + 1, 1)
Cancel = True
Application.ScreenUpdating = True

End Sub
This assumes the ID Number is in column A and only works if you double click a cell in column A.
You need to enter this code by right clicking on the tab for Sheet 1 > View code (this will open Microsoft Visual Basic, with a blank window, just paste the code in there)
Change the red parts to the actual name of the Sheet you want to paste the cells to.

Julian
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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