473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help! Excel macro to copy values from one worksheet to another

Hi... well I'm stuck. I'm hoping that someone can help me identify where I'm going wrong with the macro code I'm using...I'm working on a spreadsheet that tracks purchases. When the word "Data" is listed in Column B of sheet 1 (Instruments_TradeCalc), I want to have the values of four cells in the same row copied from Sheet1 (Instruments_TradeCalc) onto the next available row of Sheet2 (RecordPositions). The cells contain a formula so I'm looking to copy the value, not the formula - not sure if this is even possible.

I've gotten part of the way there in that I think the code is close. It doesn't return an error, but no data is copied to the subsequent work sheet (the Message Box at the end even returns "0 rows of matching data have been copied.").

I can't get it to copy and paste the data. Can someone help?

Here's what I'm currently working with:

Sub SearchForString()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim Counter As Integer

On Error GoTo Err_Execute

'Start search in row 3
LSearchRow = 3

'Start copying data to row 2 in RecordPositions (row counter variable)
LCopyToRow = 2

While Len(Range("A" & CStr(LSearchRow)).Value) > 0
With Sheets("Instruments_TradeCalc")
'If value in column B = "Data", copy entire row to RecordPositions
If .Range("B" & LSearchRow) = "Data" Then
Counter = Counter + 1

'Select row in Instruments_TradeCalc to copy and then Paste
.Range("B" & LSearchRow).Resize(1, 10).Copy Destination:=Sheets("RecordPositions").Range("B" & LCopyToRow)

'Move counter to next row
LCopyToRow = LCopyToRow + 1
End If

LSearchRow = LSearchRow + 1
End With
Wend

'Position on cell A3
Application.CutCopyMode = False
Sheets("Instruments_TradeCalc").Select
Range("A3").Select

MsgBox Counter & " rows of matching data have been copied."

Exit Sub

Err_Execute:
MsgBox "An error occurred."
Apr 28 '10 #1
2 2387
@andre0170
ok, just figured out how to get it to paste. however, still pasting formulas, not values so getting #ref errors. might have to do with paste special instead of paste... any thoughts, or code to use VB to paste special?
Apr 28 '10 #2
well, its pasting now... but only for data represented by LSearchRow = 3. AND its only pasting in the other workbook to Row 2 - it keeps overwriting.

I have 4 rows of data to search - they are specific at 3, 8, 13, and 15. The data found here should be copied and pasted to the other workbook, each in the next available row... and so on. Also, what is being pasted still contains formulas, so I am getting #ref errors. Need tounderstand how to copy and paste values only, if possible... thank you!
Apr 28 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
4
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! ...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.