VBA Code for If Else?

Malcolm torishi

Board Regular
Joined
Apr 26, 2013
Messages
219
I have the following code, in my worksheet known as “Out”, and what this code does is ever time I double click on a cell under column AB it Clears the Contents from that row, 25 cells to the left of column AB and the first 3 cells to the right of column AO on the same row. plus it paste the 1st cell value, which is my column C, into my worksheet known as “In”. So basically it’s moving names from sheet Out to sheet In.

Now what I would like the following code to do is every time I double click on a cell under column AB which then Clears the Contents from on that row, 25 cells to the left etc, I then want the code to drop a “-“ sign in to my 1st cell, which is my column C, on the row that’s been double click. Can this be done by adding an If Else type statement into the code?
If anyone can help it would be appreciated, thank you



Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 6/18/2019 3:09 PM EDT
If Target.Column = 28 And Target.Row > 1 Then
Cancel = True
Dim Lastrow As Long
Lastrow = Sheets(3).Cells(Rows.Count, "A").End(xlUp).Row + 1
Target.Offset(, -25).Resize(, 1).Copy Sheets(3).Cells(Lastrow, 1)
Target.Offset(, -25).Resize(, 25).SpecialCells(xlCellTypeConstants).ClearContents
Range("AO" & Target.Row).Resize(, 3).ClearContents
End If
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Why not just add this line, before the End If
Code:
Range("AO" & Target.Row).Resize(, 3).ClearContents
[COLOR=#ff0000]Target.Offset(, -25).Value = "-"[/COLOR]
End If
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,920
Members
448,533
Latest member
thietbibeboiwasaco

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