Changed code but still wont work

robhargreaves

Board Regular
Joined
Feb 6, 2005
Messages
85
Hi I have been using the following code to try and
achieve the following -

*If the destination cell already has a value and the form
cell is blank then do not overwrite move to the next form
entry cell.

*If the form has a value, and the destination cell has a
value display the message asking whether or not to
replace.

*If the form has a value but the destination cell does
not then enter the value then move on to the next without
messagebox.

This is the code which works perfectly but asks if I
would like to replace a value with a blank if the form
cell is empty and the destination cell has a value.

Thanks a lot for your help. I really appreciate it.

Rob

Code:
Set Rng = shData.Range("E" & Application.Match(CLng
(Sh.Range("D6")), shData.Range("B:B"), 0))
Resp = vbYes
If Rng.Value <> "" Then
  Resp = MsgBox("Digester 1 Temp Already Contains a value 
of : " & Rng.Value & " " & Chr(176) & "C" & vbCr _
             & "Would you like to change its value to : " 
& Sh.Range("D8") & " " & Chr(176) & "C", Buttons:=vbYesNo)
End If
If Resp = vbYes Then
  Rng.Value = Sh.Range("D8").Text
Else
End If

--- and this is the code i have tried to change to allow
me to take into consideration all of the 3 things at the
top of the page. Its almost as if when I tell it to goto
1 it does but then goes back up and runs through the rest
of the code too!!

Code:
Dim Rng As Range

Set Rng = shData.Range("E" & WorksheetFunction.Match
(Sh.Range("D6"), shData.Range("B:B"), 0))
Resp = vbYes
If Rng.Value = "" Then
GoTo 1
Else
End If
If Rng.Value <> "" Then
  Resp = MsgBox("Digester 1 Temp Already Contains a value 
of : " & Rng.Value & " " & Chr(176) & "C" & vbCr _
             & "Would you like to change its value to : " 
& Sh.Range("D8") & " " & Chr(176) & "C", Buttons:=vbYesNo)
End If
If Resp = vbYes Then
  Rng.Value = Sh.Range("D8").Text
Else
1
End If

Set Rng = Nothing
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,

could this structure help a bit?
Code:
If form <> "" Then
  If dest_cell = "" Then
  dest_cell = form
  Else
  If MsgBox("overwrite", 292, "title") = vbYes Then dest_cell = form
  End If
Else 'move on to next: perhaps you don't need the else part
End If
'move on

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,956
Members
449,057
Latest member
FreeCricketId

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