Not getting an error but code isn't doing what I expect...

christianbiker

Active Member
Joined
Feb 3, 2006
Messages
379
Howdy,

I am using the below code, to which I have added an if/then statement but I am not getting the results I expect and I'm not sure why. The issue relates to this part of the code:

If appealreopening.Value = "Appeal" Then Range("B" & lr).Value = PON.Value & " (" & appealreopening.Value & ")" Else
.Range("B" & lr).Value = PON.Value

During my testing the appealreopening value is "Appeal" yet the code is not adding "Appeal" to the end of the PON.value. As I said, no errors but clearly something is incorrect.

VBA Code:
  With Sheets("MAIN")
    'copy and pasted into "Sheet2" on the last row without text.
    lr = .Range("A" & Rows.Count).End(3).Row + 1
    .Range("A" & lr).Value = Disclosure.Value
    If appealreopening.Value = "Appeal" Then Range("B" & lr).Value = PON.Value & " (" & appealreopening.Value & ")" Else
    .Range("B" & lr).Value = PON.Value
    .Range("C" & lr).Value = NoticeType.Value
    .Range("D" & lr).Value = Served.Value
    .Range("E" & lr).Value = Officer.Value
    .Range("F" & lr).Value = OffenceDate.Value
    .Range("G" & lr).Value = Defendant.Value
    .Range("H" & lr).Value = Legislation.Value
    .Range("I" & lr).Value = Section.Value
    .Range("L" & lr).Value = CourtDate.Value
    .Range("M" & lr).Value = AppearanceType.Value
    .Range("N" & lr).Value = CourtLocation.Value
    .Range("O" & lr).Value = TierTime.Value
    .Range("CT" & lr).Value = ChargeType.Value
    .Range("CU" & lr).Value = Legislation.Value
    .Range("CV" & lr).Value = Section & " " & OffenceWording.Value
  End With

Thanks in advance for any assistance!!!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The comparison is case-sensitive, so maybe the value in appealreopening is spelled with a lower case 'a' instead of an upper case 'A' ?

To make the comparison case-insensitive, try the following instead...


VBA Code:
If LCase$(appealreopening.Value) = "appeal" Then

Hope this helps!
 
Upvote 0
You also haven't formed your If/Else properly.

Code:
If LCase(appealreopening.Value) = "appeal" Then
    .Range("B" & lr).Value = PON.Value & " (" & appealreopening.Value & ")"
Else
    .Range("B" & lr).Value = PON.Value
End If

'OR

.Range("B" & lr).Value = PON.Value & IIf(LCase(appealreopening.Value) = "appeal", " (Appeal)", "")

(Note the .Range, otherwise you'll write to the ActiveSheet, which may not be MAIN)
 
Last edited:
Upvote 0
Solution
You also haven't formed your If/Else properly.

Code:
If LCase(appealreopening.Value) = "appeal" Then
    .Range("B" & lr).Value = PON.Value & " (" & appealreopening.Value & ")"
Else
    .Range("B" & lr).Value = PON.Value
End If

'OR

.Range("B" & lr).Value = PON.Value & IIf(LCase(appealreopening.Value) = "appeal", " (Appeal)", "")

(Note the .Range, otherwise you'll write to the ActiveSheet, which may not be MAIN)

This worked...thanks a bunch Stephen!!!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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