Dear Sir, I Need a solution for problem Like when i click the Cells

Mohamedazees

New Member
Joined
Oct 18, 2020
Messages
43
Office Version
  1. 2019
Platform
  1. Windows
Dear Sir,
The Solution I need for when I click a any cells in Column "E,F,G to P" I need to copy and paste specific cells to another sheet for an example if I click cell "E18" I need to copy the cell value of B18 & E3 (Row 3 is my Headers) into another Sheet2 range A2 & A3. like wise if I clicks cell F18 I need to Copy & Paste Cells F18 & F3 to the Said Range ( Sheet2 Range A2 & A3) Since this range is my criteria's for my advance filter. Please ref. the attached Image that denotes the Green color cells are clickable cells and the yellow color cells need to be copy and paste to the above said range.
Thanks in Advance for your Solutions.
 

Attachments

  • Image 2.jpg
    Image 2.jpg
    163.2 KB · Views: 6

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Not sure if you need to extend the range down further than what is in the picture. If you do, I have pointed out where in the code you should increase the row number. I assume this is for a fiscal year so the number of columns will not change. The solution relies on the Worksheet_BeforeDoubleClick event so you will have to DOUBLE CLICK a cell in the green shaded area for the column and row headers to be copied to Sheet2.

Book8
ABCDEFGHIJKLMNOP
1
2
3Feb-21Mar-21Apr-21May-21Jun-21Jul-21Aug-21Sep-21Oct-21Nov-21Dec-21Jan-22
4
5
6
7
8
9
10
11
12
13
14
15
16
17Cash Paid Out
18Rental Deposits
19Retail Store - LB Road
20Retail Store - Velacherry
21Retail Store - Anna Nagar
22Dark Store - Porur
23Dark Store - Tambaram
24Dark Store - Mogappair
Sheet1


Book8
A
1
2Retail Store - Anna Nagar
34/1/2021
4
Sheet2


VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim colHeader As String, rowHeader As String
    Dim ws As Worksheet
  
   'Change the 24 in this line to how ever many rows you need  Target.Row <= 24
    If Target.Row >= 18 And Target.Row <= 24 And _
        Target.Column >= 5 And Target.Column <= 16 Then
      
        colHeader = Cells(3, Target.Column)
        rowHeader = Cells(Target.Row, 2)
      
        Set ws = Sheets("Sheet2")
      
        With ws
            .Range("A2") = rowHeader
            .Range("A3") = colHeader
        End With
  
    End If

End Sub
 
Upvote 0
I am sorry the my excepted result is not achieved in this code I fell I am not explained my problem proper way, now here with attached my mini sheets for both Sheet 1 & Sheet2 with details requirements

Sheet1:

Test copy Row & colum.xlsm
ABCDEFGHIJKLM
1
2Expense HeadAprilMayJuneJulyAugustSeptemberOctoberNovemberDecemberJanuaryFebruaryMarch
3Rent426554371231528410646267320713666390
4Depsosits207749647740710650251594580443739542
5Assets695677261379706444647368535504577748
6Laiblities510390674539470480421435327299424712
7Credits437349401667693607283685364475553226
8Debits279458722496323654407536221221411618
9Value386423406508624745613490527435476746
10Salary238376209570452478325324387755573692
11Convetance326227309547714468418434597288216444
12Depsosits259763617605238592252448598345212700
13Assets250330585467233650418270261410560361
14Laiblities698215327753270360391351757351313496
15Credits321541616402378456419286207607654224
16Debits474622512586437634648714323718476612
17Value496222716671721678717376256364633426
18Salary307557732441433504419288563291678505
19Convetance575531733587441399575466259688352609
20
21MonthExpense Head
22Cell A2Cell B2
23Example1If I Click "B4"Result in Sheet2 =AprilDepsosits
24Example2If I Click "C6"Result in Sheet2 =MayLaiblities
25Example3If I Click "D8"Result in Sheet2 =JuneDebits
26Example4If I Click "E9"Result in Sheet2 =JulyValue
Sheet1
Cell Formulas
RangeFormula
B3:M19B3=RANDBETWEEN(200,765)
G23G23=B2
H23H23=A4
G24G24=C2
H24H24=A6
G25G25=D2
H25:H26H25=A8
G26G26=E2


Sheet2:

Test copy Row & colum.xlsm
AB
1MonthExpense Head
2AprilDepsosits
Sheet2
 
Upvote 0
You're right, your first explanation was NOTHING CLOSE to what you requested in the second post and my code did EXACTLY what you asked for.

Hopefully your second explanation is closer to what you want because the code below does EXACTLY WHAT you asked for in THIS ONE.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim colHeader As String, rowHeader As String
    Dim ws As Worksheet, intsct As Range
    
    Set intsct = Intersect(Target, ActiveSheet.Range("DblClkRng"))
    
    If Not intsct Is Nothing Then
        colHeader = Cells(2, Target.Column)
        rowHeader = Cells(Target.Row, 1)
        
        Set ws = Sheets("Sheet2")
        
        With ws
            .Range("A2") = colHeader
            .Range("B2") = rowHeader
        End With
    
    End If

End Sub
 
Upvote 0
Solution
Forgot to mention, you need to create a dynamic (or static) range name call "DblClkRng" that incorporates ANYWHERE you want to be able to double click and have the data populate Sheet2 for the code to work.

Cell Formulas
RangeFormula
B3:M19B3=RANDBETWEEN(200,765)
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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