VBA help

Alisya

Well-known Member
Joined
Nov 27, 2008
Messages
532
Hi,

I am after a VBA code that will look in Col B5:B, if "N/A" found then copy the the a/c in Col C and place under the existing list in sheet "Assumptions" col C19:C and then let the user know via a msg box the new a/c ????? has been added to Assumptions.

So for the below example CITI.OPSMFI would be added to the list.

Excel Workbook
BC
5RecAccount
6CHESSCHES.0014074091
7CITIINTLCHES.0014074074
8CITIBANKCHES.0000927911
9SMPCITI.WTISII
10LIFE EXIGOCHES.0013667519
11AMPLIFE INTLCHES.0014074104
12NOMINEE EXIGOCHES.0014074082
13N/ACITI.OPSMFI
14NZACLEARCITI.ICWMAM
15
16
Sheet1
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try
Code:
Sub kpark91()
    Dim LR1 As Long, i As Long, LR2 As Long, count As Long
    LR1 = Range("A" & Rows.count).End(xlUp).Row
    LR2 = Worksheets("Assumptions").Range("A" & Rows.count).End(xlUp).Row
    If LR1 < 4 Then Exit Sub
    If LR2 < 18 Then Exit Sub
    count = LR2 + 1
    For i = 5 To LR1
        If Ucase$(Trim$(Range("B" & i).Value)) = "N/A" Then
            Worksheets("Assumptions").Range("C" & count).Value = Range("C" & i).Value
        End If
    Next i
End Sub
 
Upvote 0
I tried the code but nothing happened. Also i need the msg box to flag the user which new a/c has been added to assumptions
 
Upvote 0
Ok, i changed this to C as there is no data in A, then the code worked. Just need the msg box.

LR1 = Range("C" & Rows.count).End(xlUp).Row
 
Upvote 0
Where have you copy+pasted this code and were there anything on Assumptions worksheet?

Code:
Sub kpark91()
    Dim LR1 As Long, i As Long, LR2 As Long, count As Long, sw As Boolean
    sw = False
    LR1 = Range("C" & Rows.count).End(xlUp).Row
    LR2 = Worksheets("Assumptions").Range("C" & Rows.count).End(xlUp).Row
    If LR1 < 5 Then LR1 = 5
    If LR2 < 19 Then LR2 = 18
    count = LR2 + 1
    For i = 5 To LR1
        If Ucase$(Trim$(Range("B" & i).Value)) = "N/A" Then
            Worksheets("Assumptions").Range("C" & count).Value = Range("C" & i).Value
            sw = True
        End If
    Next i
    If sw = True Then MsgBox "New account has been added to assumptions"
End Sub

btw, are you sure you want the msgboxes to list ALL the a/c that have been added?
There might be too many to fit.
 
Upvote 0
Hi, your code fails if i have large data set i get type mismatch on this line

If Ucase$(Trim$(Range("B" & i).Value)) = "N/A" Then

Where have you copy+pasted this code and were there anything on Assumptions worksheet?

Code:
Sub kpark91()
    Dim LR1 As Long, i As Long, LR2 As Long, count As Long, sw As Boolean
    sw = False
    LR1 = Range("C" & Rows.count).End(xlUp).Row
    LR2 = Worksheets("Assumptions").Range("C" & Rows.count).End(xlUp).Row
    If LR1 < 5 Then LR1 = 5
    If LR2 < 19 Then LR2 = 18
    count = LR2 + 1
    For i = 5 To LR1
        If Ucase$(Trim$(Range("B" & i).Value)) = "N/A" Then
            Worksheets("Assumptions").Range("C" & count).Value = Range("C" & i).Value
            sw = True
        End If
    Next i
    If sw = True Then MsgBox "New account has been added to assumptions"
End Sub

btw, are you sure you want the msgboxes to list ALL the a/c that have been added?
There might be too many to fit.
 
Upvote 0
Anyone? It appears the # is causing the issue, how can this be resolved as there is always # when there is N/A.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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