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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

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