I am building a P&L on worksheet(1) based on data from worksheet(2). I need to copy rows of data from worksheet(2) and paste onto worksheet(1). The pasting process needs to find a named range (one cell) on worksheet(1) and insert a row for the copied data above the named cell. In addition, each row on worksheet(2) must first be identified by a cell value in row (d) and be pasted to a corresponding named cell.
Source = Worksheet(2)
Destination Worksheet(1)
Worksheet(2) and has hundreds of rows
Worksheet(2) column (d) has the identifier value(s), like 1000 and 1100, which both need to go to the gross sales section on worksheet(1) –the code below only has 1000.
Worksheet(1) has a named range called RPT_GS. The copied data needs to be inserted above the named range RPT_GS.
The code below is a mess and does not find the named range RPT_GS. If the below code is so ugly, please feel free to start over. I really appreciate any help. Thanks, John
Sub FIND_COPY_PASTE_1000()
Dim DestSheet As Worksheet
Set DestSheet = Worksheets("sheet 1")
Dim sRow As Long
Dim dRow As Long
Dim sCount As Long
sCount = 0
dRow = 1
For sRow = 1 To Range("D360").End(xlUp).Row
If Cells(sRow, "D") Like "1000" Then
sCount = sCount + 0
dRow = dRow + 1
'Cells(sRow, "F").Copy Destination:=DestSheet.Cells(dRow, "B")
'Cells(sRow, "E").Copy Destination:=DestSheet.Cells(dRow, "C")
'Cells(sRow, "D").Copy Destination:=DestSheet.Cells(dRow, "D")
End If
Next sRow
4 4001
I am building a P&L on worksheet(1) based on data from worksheet(2). I need to copy rows of data from worksheet(2) and paste onto worksheet(1). The pasting process needs to find a named range (one cell) on worksheet(1) and insert a row for the copied data above the named cell. In addition, each row on worksheet(2) must first be identified by a cell value in row (d) and be pasted to a corresponding named cell.
Source = Worksheet(2)
Destination Worksheet(1)
Worksheet(2) and has hundreds of rows
Worksheet(2) column (d) has the identifier value(s), like 1000 and 1100, which both need to go to the gross sales section on worksheet(1) –the code below only has 1000.
Worksheet(1) has a named range called RPT_GS. The copied data needs to be inserted above the named range RPT_GS.
The code below is a mess and does not find the named range RPT_GS. If the below code is so ugly, please feel free to start over. I really appreciate any help. Thanks, John
Sub FIND_COPY_PASTE_1000()
Dim DestSheet As Worksheet
Set DestSheet = Worksheets("sheet 1")
Dim sRow As Long
Dim dRow As Long
Dim sCount As Long
sCount = 0
dRow = 1
For sRow = 1 To Range("D360").End(xlUp).Row
If Cells(sRow, "D") Like "1000" Then
sCount = sCount + 0
dRow = dRow + 1
'Cells(sRow, "F").Copy Destination:=DestSheet.Cells(dRow, "B")
'Cells(sRow, "E").Copy Destination:=DestSheet.Cells(dRow, "C")
'Cells(sRow, "D").Copy Destination:=DestSheet.Cells(dRow, "D")
End If
Next sRow
Is it not working or something? Not sure what the issue is.
I am building a P&L on worksheet(1) based on data from worksheet(2). I need to copy rows of data from worksheet(2) and paste onto worksheet(1). The pasting process needs to find a named range (one cell) on worksheet(1) and insert a row for the copied data above the named cell. In addition, each row on worksheet(2) must first be identified by a cell value in row (d) and be pasted to a corresponding named cell.
...
Your code doesnt seem that bad; the problems i think you might be having are: - When you run the code, you have to make sure your active sheet is the second, or (a better solution) use it as the parent of the cells while searching.
- Range("D360").End(xlUp).Row means: You stand in cell D360, then you press Ctrl+upArrow and then you see the row number. If you have no empty spaces in column D, that'll be the first row, and your FOR will go from 1 to 1. Maybe you want to use .End(xlDown)
- When you make the copy-paste, you're not inserting a new row, may be you want to insert it before you copy-paste.
With some luck, something like this will solve this three problems: - Sub FIND_COPY_PASTE_1000()
-
-
Dim DestSheet As Worksheet
-
Set DestSheet = Worksheets("sheet 1")
-
-
Dim sRow As Long
-
Dim dRow As Long
-
Dim sCount As Long
-
sCount = 0
-
dRow = 1
-
with worksheets("sheet2")
-
For sRow = 1 To Range("D360").End(-4121).Row '-4121 is the numerical value of xlDown, inside excel, they're the same, outside excel, only the numeric value is good.
-
If .Cells(sRow, "D") Like "1000" Then
-
sCount = sCount + 0
-
dRow = dRow + 1
-
Rows(dRow).Insert Shift:=-4121
-
.Cells(sRow, "F").Copy Destination:=DestSheet.Cells(dRow, "B")
-
.Cells(sRow, "E").Copy Destination:=DestSheet.Cells(dRow, "C")
-
.Cells(sRow, "D").Copy Destination:=DestSheet.Cells(dRow, "D")
-
End If
-
Next sRow
-
end with
-
end sub
Sorry, the problem is when the 1000 value is found in sheet2 row d, i need the macro to insert a row for each time it finds a 1000 (and copy the entire row the 1000 is contained in).
Thanks!
Sorry, the problem is when the 1000 value is found in sheet2 row d, i need the macro to insert a row for each time it finds a 1000 (and copy the entire row the 1000 is contained in).
Thanks!
the code i've just posted will do that ^.^
just change the .end(-4121) to your original .end(xlup)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Edward Diener |
last post by:
Coming from the C++ world I can not understand the reason why copy
constructors are not used in the .NET framework. A copy constructor creates
an object from a copy of another object of the same...
|
by: Daniel Tan |
last post by:
Are there anyway to copy rows of records from one query to another
query and then hide the records in source query ? Pls advise. Thanks.
Regards,
Daniel
|
by: david |
last post by:
Hi,
I've been reading tons of posts on how to copy records, but to no
avail....i'm still stuck.
There are three tables: Main, Sub-Form1 & Sub-Form2
I have a form which displays some data....
|
by: Paul |
last post by:
public class A
{
public A ()
{
// here I would like to call the second version of _ctor, how to
accomplish this ?
}
public A (int a, int b, int c)
{
|
by: michael sorens |
last post by:
I tried to do a simple operation on a Windows Form in VS2005 inside a
key_down handler:
if (e.Control && e.Shift && e.KeyCode == Keys.V)
{
int selectedRowIndex =...
|
by: jmpigott |
last post by:
I have searched forever trying to solve a problem that simplifies recurring info inputs to my database
the basic structure is Orders tbl main form and pricing_tbl subform and third when orders...
|
by: Taxman |
last post by:
Windows XP, MS Office Excel 2003
If the tasks, I’m trying accomplish have been addressed previously (separately or in combination). Please, provide the links or keyword search to find them. I’ve...
|
by: barkarlo |
last post by:
I make pivot table in excel.
in page field is item month.
in row field is employees.
in column field is working hours,sunday hours, overtime and ect.
Now I want with VBA code copy/paste only...
|
by: Deven Oza |
last post by:
Hi,
Does anyone have an idea that how to copy column(s) from one excel sheet to another sheet using sql server.
Thanks for your help in advance.
-Deven
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |