How to Call a Macro with tow conditions

azad092

Board Regular
Joined
Dec 31, 2019
Messages
198
Office Version
  1. 2007
Platform
  1. Windows
Hi
I am using the given code to call a macro
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$D$4" Then
Call DataEntryToExpense
End If
End Sub
I want to add one more condition to call the macro
first condition is the specific word in the cell B4 and the second condition is d4
so when B4 have a specific and and the D4 have the specific word then the macro should be run
please guide me in this issue
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
can you add an "AND" statement to your existing code?
is the specific word always the same or do you mean if b4 contains the same word as d4?
 
Upvote 0
can you add an "AND" statement to your existing code?
is the specific word always the same or do you mean if b4 contains the same word as d4?
thanks for you kind attention
actually i have some data sheets... from the main sheet i want to transfer data by using macro...
so B4 is a dropdown list of different sheets and d4 is for post the data into the concerned sheet
 
Upvote 0
If you want to search "Hello" partial match in B4 then

VBA Code:
f Target.Address = "$D$4" And Instr(range("B4").value, "Hello")>0 Then
 
Upvote 0
If you want to search "Hello" partial match in B4 then

VBA Code:
f Target.Address = "$D$4" And Instr(range("B4").value, "Hello")>0 Then
I apply the given code but it return the code as shown in the image
compile error.JPG
 
Upvote 0
If you want to search "Hello" partial match in B4 then

VBA Code:
f Target.Address = "$D$4" And Instr(range("B4").value, "Hello")>0 Then
compile error.JPG
I apply the given code but it return the code as shown in the image, even when i click in a cell this compile error shows
 
Upvote 0
The macro "DataEntryToUtilities" may not work properly.
Could you share that macro?
 
Upvote 0
The macro "DataEntryToUtilities" may not work properly.
Could you share that macro?
yes this macro work properly... even if I run it directly or call it after single if condition then it works but after the double condition its not working
 
Upvote 0
The macro "DataEntryToUtilities" may not work properly.
Could you share that macro?
VBA Code:
Option Base 1
Sub DataEntryToUtelities()
    Dim EntryCell   As Range, DataEntryRange As Range
    Dim wsUtelities       As Worksheet
    Dim NextRow     As Long
    Dim Arr         As Variant
    Dim i           As Integer
    
    With ThisWorkbook
        'cells to copy from Data Entry sheet
        Set DataEntryRange = .Worksheets("DASHBOARD").Range("A4:D4")
        ' database sheet
        Set wsUtelities = .Worksheets("Utelities")
    End With
    
    'database ranges to send data entry values
    Arr = Array("A", "B", "C", "D")
    
    'output array to database range
    With wsUtelities
        NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        
        For Each EntryCell In DataEntryRange.Cells
            i = i + 1
            .Cells(NextRow, Arr(i)).Value = EntryCell.Value
            EntryCell.ClearContents
        Next
    End With
    
    'inform user
    MsgBox "New Record In Expense Has been Posted Succussfully", 64, "DOCTOR'S LAB (Utelities)"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,451
Members
449,161
Latest member
NHOJ

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