Conditionally Transfer Data Using VBA

azad092

Board Regular
Joined
Dec 31, 2019
Messages
198
Office Version
  1. 2007
Platform
  1. Windows
VBA Code:
Option Base 1
Sub DataEntryToExpense()
    Dim EntryCell   As Range, DataEntryRange As Range
    Dim wsExpense       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:C4")
        ' database sheet
        Set wsExpense = .Worksheets("Expense")
    End With
    
    'database ranges to send data entry values
    Arr = Array("A", "B", "C")
    
    'output array to database range
    With wsExpense
        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 (EXPENSE)"
End Sub
Hi
good morning
I am using this VBA code for posting data from sheet one sheet to another
I want to do this with a condition
I want when I enter a specific word (sheet name) in column B4, the data should be posted in the concerned sheet
please guide how I can do this
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,216,252
Messages
6,129,717
Members
449,529
Latest member
SCONWAY

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