Advice to remove redundant line of code currently in use

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
I am using the code below.

On my worksheet in cell B3 i used to enter a month.
When i typed APRIL i would see a userform pop up "APRILFORM.Show" but now this isnt required so i need to remove that part of the code.
In the code below i have removed the part shown in Red BUT i keep seeing the msgbox "DOES NOT EXIST"

Please advise if i removed something i shouldnt have or do i also need to remove something else ?

Basically there is no need know to lookif APRIL is in the cell & pop up the Msgbox

Rich (BB code):
Private Sub SUMMARYTRANSFER()
    Dim rFndCell As Range
    Dim strData As String
    Dim stFnd As String
    Dim fRow As Long
    Dim sh As Worksheet
    Dim ws As Worksheet
    Dim strDate As String

    Set ws = Sheets("G INCOME")
    Set sh = Sheets("G SUMMARY")
    stFnd = ws.Range("A3").Value
    strDate = ws.Range("A5").Value
        With sh
    If Range("A3").Value = "APRIL" Then
        APRILFORM.Show
    Else

        Set rFndCell = .Range("C6:C16").Find(stFnd, LookIn:=xlValues)
        If Not rFndCell Is Nothing Then
            fRow = rFndCell.Row
            If CDate(strDate) > CDate("05/04/2023") Then
                sh.Cells(fRow, 4).Resize(, 1).Value = ws.Range("D31").Value
                sh.Cells(fRow, 5).Resize(, 1).Value = ws.Range("E31").Value
            Else:

            End If
            MsgBox "TRANSFER TO SUMMARY SHEET ALSO COMPLETED", vbInformation + vbOKOnly, "SUMMARY TO TRANSFER SHEET COMPLETED MESSAGE"
        Else
            MsgBox "DOES NOT EXIST", vbCritical + vbOKOnly, "SUMMARY TO TRANSFER SHEET FAILED MESSAGE"
            Range("A5").Select
        End If
        Range("A3:B3").ClearContents
        Range("E3").ClearContents
        Range("C3").ClearContents
        Range("A5:B30").ClearContents
        Range("A5:A30").NumberFormat = "@"
        Range("A5").Select
        ActiveWorkbook.Save
        
    End If
    End With
    
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Which sheet is this referring to?
VBA Code:
Set rFndCell = .Range("C6:C16").Find(stFnd, LookIn:=xlValues)
 
Upvote 0
Basically in the cell B3 every other month would be found on the G SUMMARY sheet & saved.
If i have entered APRIL i would see a userform

I have now changed something so there is no need for me to see that userform.
Thus is should now just continue as if it was MAY or OCTOBER etc
 
Upvote 0
try
VBA Code:
Set rFndCell = sh.Range("C6:C16").Find(stFnd, LookIn:=xlValues)
 
Upvote 0
But i need to remove that redundant code.
I dont need to see

Rich (BB code):
   If Range("A3").Value = "APRIL" Then
        APRILFORM.Show
 
Upvote 0
But i need to remove that redundant code.
I dont need to see

Rich (BB code):
   If Range("A3").Value = "APRIL" Then
        APRILFORM.Show
I thought you said you kept getting the msgbox "DOES NOT EXIST"
 
Upvote 0
I removed a part of the code.
I then keep getting the DOES NOT EXIST MESSAGE
So i thought i had left somethuing behind.
I put what i removed back & now the code runs.

So forget the DOES NOT EXIST MESSAGE

Please advise what i need to remove so the code just runs as if i had entered MAY so i can try it
 
Upvote 0
try

VBA Code:
Private Sub SUMMARYTRANSFER()
    Dim rFndCell As Range
    Dim strData As String
    Dim stFnd As String
    Dim fRow As Long
    Dim sh As Worksheet
    Dim ws As Worksheet
    Dim strDate As String

    Set ws = Sheets("G INCOME")
    Set sh = Sheets("G SUMMARY")
    stFnd = ws.Range("A3").Value
    strDate = ws.Range("A5").Value
    With sh
'    If Range("A3").Value = "APRIL" Then
'        APRILFORM.Show
'    Else

        Set rFndCell = .Range("C6:C16").Find(stFnd, LookIn:=xlValues)
        If Not rFndCell Is Nothing Then
            fRow = rFndCell.Row
            If CDate(strDate) > CDate("05/04/2023") Then
                sh.Cells(fRow, 4).Resize(, 1).Value = ws.Range("D31").Value
                sh.Cells(fRow, 5).Resize(, 1).Value = ws.Range("E31").Value
            Else:

            End If
            MsgBox "TRANSFER TO SUMMARY SHEET ALSO COMPLETED", vbInformation + vbOKOnly, "SUMMARY TO TRANSFER SHEET COMPLETED MESSAGE"
        Else
            MsgBox "DOES NOT EXIST", vbCritical + vbOKOnly, "SUMMARY TO TRANSFER SHEET FAILED MESSAGE"
            Range("A5").Select
        End If
        Range("A3:B3").ClearContents
        Range("E3").ClearContents
        Range("C3").ClearContents
        Range("A5:B30").ClearContents
        Range("A5:A30").NumberFormat = "@"
        Range("A5").Select
        ActiveWorkbook.Save
        
'    End If
    End With
    
End Sub
 
Upvote 0
Solution
That worked thanks.

So what i did wrong was to delete by mistake With sh
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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