GManbright
New Member
- Joined
- Jan 22, 2023
- Messages
- 1
- Office Version
- 365
- 2019
- Platform
- Windows
Good afternoon everyone. I have the following two VBA functions and need help combining them so that I can use both in the same workbook. I would really appreciate it if someone can help me with this. Thanks so much!
FIRST FUNCTION:
SECOND FUNCTION:
Thanks in advance!
FIRST FUNCTION:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim sh1 As Worksheet, sh2 As Worksheet
Dim rng As Range, r As Range
Set sh1 = ThisWorkbook.Sheets("Sheet1")
Set sh2 = ThisWorkbook.Sheets("Sheet2")
If Target.Address = "$A$2" Then
Set rng = sh2.Range("A:A").Find(Target.Value)
If Not rng Is Nothing Then
Set r = rng
Do
If r.Address = rng.Address Then
r.EntireRow.Copy sh1.Range("A" & Target.Row + 1)
Else
r.EntireRow.Copy sh1.Range("A" & Target.Row + r.Row - rng.Row + 1)
End If
Set r = sh2.Range("A:A").FindNext(r)
Loop Until r.Address = rng.Address
End If
Else
Set rng = sh1.Range("A:A").Find(Target.Value)
If Not rng Is Nothing Then
Set r = rng
Do
If r.Address = rng.Address Then
r.EntireRow.Delete
Else
r.EntireRow.Delete
End If
Set r = sh1.Range("A:A").FindNext(r)
Loop Until r Is Nothing
End If
End If
End Sub
SECOND FUNCTION:
VBA Code:
Sub Worksheet_BeforeDoubleClick(ByVal Target As Range)
Dim sh1 As Worksheet, sh2 As Worksheet
Dim col2 As Integer, col1 As Integer
Set sh1 = ThisWorkbook.Sheets("Sheet1")
Set sh2 = ThisWorkbook.Sheets("Sheet2")
If Target.Address = "$B$3" Then
col2 = Application.Match(sh1.Range("B32").Value, sh2.Range("B1:AB1"), 0)
If Not IsError(col2) Then
sh2.Range(sh2.Cells(2, col2), sh2.Cells(2, col2 + 100)).EntireColumn.Copy
sh1.Range("B3").Insert Shift:=xlToRight
End If
Else
col1 = Application.Match(Target.Value, sh1.Range("B1:AB1"), 0)
If Not IsError(col1) Then
sh1.Range(sh1.Cells(3, col1), sh1.Cells(3, col1 + 100)).EntireColumn.Delete
End If
End If
End Sub
Thanks in advance!
Last edited by a moderator: