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

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.
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,223,952
Messages
6,175,596
Members
452,657
Latest member
giadungthienduyen

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