VBA code required for Msg Box when two value equal in two cells

Try this: Private Sub Worksheet_Change(ByVal Target As Range) If Range(“A” & Target.Row) = Range(“B” & Target.Row) Then MsgBox “Buy – ” & Range(“E” & Target.Row) ElseIf Range(“A” & Target.Row) = Range(“C” & Target.Row) Then MsgBox “Sell – ” & Range(“E” & Target.Row) End If End Sub The key is using the Worksheet_Change event in the … Read more

VBA code takes long time to execute in excel

The first thing I do to speed up VBA like this is to use Screen Updating Sub LOOK() Application.ScreenUpdating = False Worksheets(“Input”).Unprotect (“ds12345”) Dim found As Range Set found = Sheets(“Records”).Columns(“D”).Find(What:=ActiveSheet.Cells(3, 13).Value, SearchDirection:=xlPrevious, LookIn:=xlValues, LookAt:=xlWhole) If found Is Nothing Then MsgBox “Not found” Else MsgBox “Found on row ” & found.Row End If Dim iRow … Read more

Rearranging Excel Cell based on Value [closed]

This sub procedure works with two variant arrays. Option Explicit Sub Macro3() Dim i As Long, j As Long, nr As Long Dim tmp As Variant, arr As Variant, hdr As Variant, vals As Variant With Worksheets(“sheet4”) tmp = .Cells(1, “A”).CurrentRegion ReDim vals(LBound(tmp, 1) To UBound(tmp, 1), LBound(tmp, 2) To UBound(tmp, 2)) nr = UBound(tmp, … Read more

to make this code simpler

Something like this: Sub Macro1() Dim Sh1 As WorkSheet, Sh2 As WorkSheet Set Sh1 = Sheets(“Sheet1”) Set Sh2 = Sheets(“ALB1”) Dim R As Long For R = 2 to 127 Sh1.Range(“D” & R & “:E” & R).Copy Sh2.Range(“C” & R – 1) Next R End Sub Or even better: Sheets(“ALB1”).Range(“C1:D126”) = “=Sheet1!D2” Assigning a formula … Read more