atifmehmood
New Member
- Joined
- Apr 27, 2020
- Messages
- 1
- Office Version
- 2010
- Platform
- Windows
Hi
I am new to VBA for excel and I am trying to transfer a data from master sheet which contains expenses for different dates and for every date I have a separate sheet where I want to transfer expenses from master sheet named "Data Entry". the problem with my code is that when I transfer amount and description from master sheet todestination sheet it works for column A but when I want to change code for destination as column B it run for only one entry and then left the all others I have lot of destination sheets and lot of entries for every sheet please help me in solving keeping my format for sheets in consideration.I am attaching the VBA code as well as Snaps of my sheet.
""""""Sub copyPasteData()
Dim strSourceSheet As String
Dim strDestinationSheet As String
Dim lastRow As Long
strSourceSheet = "Data entry"
Sheets(strSourceSheet).Visible = True
Sheets(strSourceSheet).Select
Range("B2").Select
Do While ActiveCell.Value <> ""
strDestinationSheet = ActiveCell.Value
ActiveCell.Offset(0, 1).Resize(1, 2).Select
Selection.Copy
Sheets(strDestinationSheet).Visible = True
Sheets(strDestinationSheet).Select
lastRow = LastRowInOneColumn("A")
Cells(lastRow + 1, 1).Select
Selection.PasteSpecial xlPasteAll
Application.CutCopyMode = False
Sheets(strSourceSheet).Select
ActiveCell.Offset(0, -1).Select
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Public Function LastRowInOneColumn(col)
'Find the last used row in a Column: column A in this example
Dim lastRow As Long
With ActiveSheet
lastRow = .Cells(.Rows.Count, col).End(xlUp).Row
End With
LastRowInOneColumn = lastRow
End Function""""
I am new to VBA for excel and I am trying to transfer a data from master sheet which contains expenses for different dates and for every date I have a separate sheet where I want to transfer expenses from master sheet named "Data Entry". the problem with my code is that when I transfer amount and description from master sheet todestination sheet it works for column A but when I want to change code for destination as column B it run for only one entry and then left the all others I have lot of destination sheets and lot of entries for every sheet please help me in solving keeping my format for sheets in consideration.I am attaching the VBA code as well as Snaps of my sheet.
""""""Sub copyPasteData()
Dim strSourceSheet As String
Dim strDestinationSheet As String
Dim lastRow As Long
strSourceSheet = "Data entry"
Sheets(strSourceSheet).Visible = True
Sheets(strSourceSheet).Select
Range("B2").Select
Do While ActiveCell.Value <> ""
strDestinationSheet = ActiveCell.Value
ActiveCell.Offset(0, 1).Resize(1, 2).Select
Selection.Copy
Sheets(strDestinationSheet).Visible = True
Sheets(strDestinationSheet).Select
lastRow = LastRowInOneColumn("A")
Cells(lastRow + 1, 1).Select
Selection.PasteSpecial xlPasteAll
Application.CutCopyMode = False
Sheets(strSourceSheet).Select
ActiveCell.Offset(0, -1).Select
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Public Function LastRowInOneColumn(col)
'Find the last used row in a Column: column A in this example
Dim lastRow As Long
With ActiveSheet
lastRow = .Cells(.Rows.Count, col).End(xlUp).Row
End With
LastRowInOneColumn = lastRow
End Function""""