VBA Copy and Paste Macro doesnt line up correctly

LostInEverything

New Member
Joined
May 27, 2024
Messages
3
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
Hi,

To begin with I'm quite new to excel VBA and trying to learn it as I go, so if anyone has good starting points or materials I would love to see them.

But onto my actual question. I am trying to make a spreadsheet that uses a macro to send info form specific cells in another sheet to a second. Now I have managed to make that happen, but the way I have to do it requires me to separate the copy and paste action. Therefore, I am encountering an issue where the data doesnt line up as I want it to.

It comes out like this:
1716790790566.png


When I need it to look like this:
1716791023637.png


This is the code I am using:

Sub Copy3()

If IsEmpty(Sheets("SourceSheet").Range("D2:D3").Value) Then
End
Else: Sheets("SourceSheet").Select
Range("D2:D3").Select
Selection.Copy
Sheets("TargetSheet").Select
Sheets("TargetSheet").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True

End If

If IsEmpty(Sheets("SourceSheet").Range("B7:C10").Value) Then
End
Else: Sheets("SourceSheet").Select
Range("B7:C10").Select
Selection.Copy
Sheets("TargetSheet").Select
Sheets("TargetSheet").Range("D" & Rows.Count).End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

End If

End Sub

If anyone knows a way to solve this, it would be greatly appreciated.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Welcome to the Forum.
Please show us what the source data looks like ideally using the Forum's XL2BB to save us having to manually create test data.
If you have to use an image please include the row and column references.

Using XL2BB
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Book1.xlsm
ABCDEF
1
2Date27/05/2024 20:27
3SellerSeller1
4Price$ 30.00
5
6productamountprice
7Item1120
8Item2210
9
10
SourceSheet
Cell Formulas
RangeFormula
D2D2=NOW()
D4D4=SUM(D7:D8)
Cells with Data Validation
CellAllowCriteria
D3ListSeller1, Seller2


Book1.xlsm
ABCDEFG
1
2DateSellerProductAmountPrice
327/05/2024 20:27Seller1Item11
4Item22
5
6
7
8
9
TargetSheet
Cell Formulas
RangeFormula
B3B3=NOW()
Cells with Data Validation
CellAllowCriteria
C7ListSeller1, Seller2
C5ListSeller1, Seller2
C3ListSeller1, Seller2


Is this what you meant? Does this help?
 
Upvote 0
Sorry I completely forgot a piece of information that probably helps. The SourceSheet is meant to act as a sale form where that is the only data on that sheet. the area where it says seller is meant to be able to be swapped between both seller 1 and 2. Additionally there is a save button that runs a macro using the code from earlier next to it, it just didnt copy over for some reason. So basically in sourcesheet you only change out what is needed and hit save and it puts it in targetsheet, however when it runs it comes out with the issue I had in my intital post. If that is clear?
 
Upvote 0

Forum statistics

Threads
1,216,499
Messages
6,131,012
Members
449,613
Latest member
MedDash99

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