VBA reading cell value not formula

ClaireLou

New Member
Joined
Nov 14, 2020
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi

I have the code attached, its an auto sheet event script

How do I get the vba code to read the value and not the formula? I need it to move the rows depending on the status in column A and that changes based on the values in other columns.
I’ve put the code I’m using below. It works perfectly if I actually type in the phrase I’m using.
Thanks for any help ?
Claire

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Application.ScreenUpdating = False
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrowa = Sheets("Sheet3").Cells(Rows.Count, "A").End(xlUp).Row + 1
If Target.Value = "To be Booked" Then
Rows(Target.Row).Copy Destination:=Sheets("Sheet2").Rows(Lastrow)
Application.EnableEvents = False
Rows(Target.Row).Delete
Application.EnableEvents = True
Exit Sub
End If
Application.EnableEvents = True
If Target.Value = "Booked" Then
Rows(Target.Row).Copy Destination:=Sheets("Sheet3").Rows(Lastrowa)
Application.EnableEvents = False
Rows(Target.Row).Delete
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Change events do not get triggered by a formula.
Does the formula in col A look only at that sheet, or does it depend on values on another sheet?
 
Upvote 0
Change events do not get triggered by a formula.
Does the formula in col A look only at that sheet, or does it depend on values on another sheet?
Hi
It only looks at the one sheet
Thanks
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim KyCell As Range
   
   If Target.CountLarge > 1 Then Exit Sub
   Set KyCell = Range("A:A")
   On Error Resume Next
   Set KyCell = Union(KyCell, KyCell.Precedents)
   On Error GoTo 0
   If Not Intersect(Target, KyCell) Is Nothing Then
      Select Case Range("A" & Target.Row).Value
         Case "To be Booked"
            With Target.EntireRow
               .Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
               .Delete
            End With
         Case "Booked"
            With Target.EntireRow
               .Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1)
               .Delete
            End With
      End Select
   End If
End Sub
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim KyCell As Range
  
   If Target.CountLarge > 1 Then Exit Sub
   Set KyCell = Range("A:A")
   On Error Resume Next
   Set KyCell = Union(KyCell, KyCell.Precedents)
   On Error GoTo 0
   If Not Intersect(Target, KyCell) Is Nothing Then
      Select Case Range("A" & Target.Row).Value
         Case "To be Booked"
            With Target.EntireRow
               .Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
               .Delete
            End With
         Case "Booked"
            With Target.EntireRow
               .Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1)
               .Delete
            End With
      End Select
   End If
End Sub
It’s not doing anything. Now when I change the target cell manually, it’s not changing either
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub


Application.ScreenUpdating = False
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrowa = Sheets("Sheet3").Cells(Rows.Count, "A").End(xlUp).Row + 1
If Target.Value = "To be Booked" And Target.HasFormula = False Then

Rows(Target.Row).Copy Destination:=Sheets("Sheet2").Rows(Lastrow)
MsgBox Rows(Target.Row).Address
Exit Sub

Application.EnableEvents = False
Rows(Target.Row).Delete
Application.EnableEvents = True
End If
Application.EnableEvents = True
If Target.Value = "Booked" And Target.HasFormula = False Then
Rows(Target.Row).Copy Destination:=Sheets("Sheet3").Rows(Lastrowa)
Application.EnableEvents = False
Rows(Target.Row).Delete
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
 
Upvote 0
I think it might be the entry of multiple cells at once. Do you guys know a better code, even one that I have to run manually, that will move the row based on the output in column A? Booked & To be booked still need to go to separate sheets and blank to stay on the original. Thanks
 
Upvote 0
What is the name of the sheet that has the data?
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,222
Members
448,877
Latest member
gb24

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