How to delete a value from a cell in VBA

kev_bez

New Member
Joined
Jul 20, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Good afternoon all, Newbie here trying to make some code that I have copied work. Everything works apart from it doesn't delete the value from the cell of the last selection. It deletes all the previous ones. This is the code

Sub PrintCWO()
If Not ActiveSheet.Name Like "WK*" Then
MsgBox "Ensure correct worksheet selected"
Exit Sub

Application.ScreenUpdating = False

Else:
Count = 1
For i = 4 To 500

If LCase(Range("BB" & i).Value) = "y" Then

Area = Range("A" & i).Value
Zone = Range("B" & i).Value
Station = Range("C" & i).Value
Robot = Range("D" & i).Value
Desc = Range("E" & i).Value
Ref = Range("F" & i).Value
ReqDate = Range("G" & i).Value
Requestor = Range("H" & i).Value
Trades = Range("I" & i).Value
Gap = Range("J" & i).Value
Stoppage = Range("K" & i).Value
Priority = Range("L" & i).Value
Order = Range("N" & i).Value
Est = Range("T" & i).Value
Authorised = Range("BA" & i).Value

Sheets("CWO").Range("B1").Value = Area
Sheets("CWO").Range("C1").Value = Zone
Sheets("CWO").Range("D1").Value = Station
Sheets("CWO").Range("E1").Value = Robot
Sheets("CWO").Range("F1").Value = Desc
Sheets("CWO").Range("G1").Value = Ref
Sheets("CWO").Range("H1").Value = ReqDate
Sheets("CWO").Range("I1").Value = Requestor
Sheets("CWO").Range("J1").Value = Trades
Sheets("CWO").Range("K1").Value = Gap
Sheets("CWO").Range("L1").Value = Stoppage
Sheets("CWO").Range("M1").Value = Priority
Sheets("CWO").Range("O1").Value = Order
Sheets("CWO").Range("U1").Value = Est
Sheets("CWO").Range("V1").Value = Authorised

If Count = 1 Then
x = ActiveSheet.Name
Sheets("CWO").Activate
Application.Dialogs(xlDialogPrint).Show
Sheets(x).Activate
Else: Sheets("CWO").PrintOut
End If

Count = Count + 1
Range("BB" & i).Value = ""

End If

Next

End If

Application.ScreenUpdating = True
End Sub

Can anybody help please?
Thank you!
 
You are welcome.

I suspect the bouncing around between sheets was the issue.
By qualifying the sheet along with the range, we can tell it exactly which sheet we want to update.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You are welcome.

I suspect the bouncing around between sheets was the issue.
By qualifying the sheet along with the range, we can tell it exactly which sheet we want to update.
Yes you're correct, I noticed just as you posted the solution that cell BB was being cleared on sheet "CWO" rather than the active sheet. Valuable lesson learnt! Thanks again!
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,952
Members
449,095
Latest member
nmaske

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