Adding to Code

Regtompj

New Member
Joined
Jul 4, 2010
Messages
37
I have used the below code it most of my work, but when the cell is clicked and highlighted can it also reference the name in that cell and add it to the title in a specified row?

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim c As Range
Dim FirstAddress As String
Static ColIdx
Cancel = True
If IsEmpty(ColIdx) Then ColIdx = 33 Else ColIdx = ColIdx + 1
If ColIdx > 46 Then ColIdx = 33
ActiveCell.Interior.ColorIndex = ColIdx
With Range("A5:R62")
  Set c = .Find(ActiveCell.Value, LookIn:=xlValues)
  If Not c Is Nothing Then
    FirstAddress = c.Address
    Do
      c.Interior.ColorIndex = ColIdx
      Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> FirstAddress
  End If
End With
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I just added the below code to copy and paste the double click cell (cells range from A5:R62) to another merged cell (A2), i am getting a "compile error" any ideas?
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim c As Range
Dim FirstAddress As String
Static ColIdx
Cancel = True
If IsEmpty(ColIdx) Then ColIdx = 33 Else ColIdx = ColIdx + 1
If ColIdx > 46 Then ColIdx = 33
ActiveCell.Interior.ColorIndex = ColIdx
With Range("A5:R62")
  Set c = .Find(ActiveCell.Value, LookIn:=xlValues)
  If Not c Is Nothing Then
    FirstAddress = c.Address
    Do
      c.Interior.ColorIndex = ColIdx
      Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> FirstAddress
  End If
End With
End Sub
 
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Dim rng As Range
Set rng = Range(ActiveCell, ActiveCell.Offset(0,))
rng.Copy Destination:=ActiveCell.Offset(1, 2)
End Sub
 
Upvote 0
You cannot have to like-named procedures in the same module. This includes event procedures such as Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
 
Upvote 0
Try removing the first End Sub and the last Private... so you only have one procedure?
 
Upvote 0
Try

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim c As Range
Dim FirstAddress As String
Static ColIdx
Cancel = True
If IsEmpty(ColIdx) Then ColIdx = 33 Else ColIdx = ColIdx + 1
If ColIdx > 46 Then ColIdx = 33
Target.Interior.ColorIndex = ColIdx
With Range("A5:R62")
  Set c = .Find(Target.Value, LookIn:=xlValues)
  If Not c Is Nothing Then
    FirstAddress = c.Address
    Do
      c.Interior.ColorIndex = ColIdx
      Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> FirstAddress
  End If
End With
Target.Copy Destination:=Target.Offset(1, 2)
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,190
Messages
6,129,421
Members
449,509
Latest member
ajbooisen

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