473,388 Members | 1,209 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,388 software developers and data experts.

Excel macro-- copy cell to same column in next row

I'm sure this is very simple, but I'm just starting with these types of tasks. I need to copy a cell value to the same column in the next row and cycle thru all data. I can use this twice to do this for 2 different columns or combine these two steps into one. More specifically: I need to copy cell A1 to B1 (etc.) and copy cell D1 to D2 (etc.)--all on the same worksheet. These 2 copy/paste operations need to continue until there is no data--which will happend at the same time for both sets. Any help is gresatly appreciated--I want to make this task faster and less boring!
Oct 5 '12 #1
11 5455
twinnyfo
3,653 Expert Mod 2GB
spmartin2012,

Although this is an Access VBA forum, please describe your data set. I'm not sure I follow what needs to happen, as the A1 to B1 copies data one cell to the right, and D1 to D2 copies data one cell down. I'm not sure I understand how to continue that until there is no data.....

Please explain, providing a sample of your data.
Oct 5 '12 #2
Sorry for the typo--I want to copy both cells downward, starting with A1 and D1 and repeating until there is no data. I have already used a macro to insert a blank line below each original row, so there are blank rows in which to paste the copy of the cell value. Columns A and D will always have the same value in the newly created row as the row above. The other columns are for manually entered data. THANKS so much for any help!
Oct 5 '12 #3
Rabbit
12,516 Expert Mod 8TB
What code do you have so far?
Oct 5 '12 #4
I'm playing around with it:

Expand|Select|Wrap|Line Numbers
  1. Dim h As Long, r2 As Range
  2. h = 1   'InputBox("type the number of rows to be insered")
  3.  
  4. Set r2 = Range("A1")
  5. Do
  6. Range(r2.Copy, A2, Offset(1, 0)).PasteSpecial , xlPasteSpecialOperationNone
  7.  
  8. Set r2 = Cells(r2.Cells.Value + h + 1, 1)
  9.  
  10. If r2.Offset(1, 0) = "" Then Exit Do
  11.  
  12. Loop
Oct 5 '12 #5
Another typo, it is:

Expand|Select|Wrap|Line Numbers
  1. Dim h As Long, r2 As Range
  2. h = 1  
  3.  
  4. Set r2 = Range("A1")
  5. Do
  6. Range(r2.Copy, A2, Offset(1, 0)).PasteSpecial , xlPasteSpecialOperationNone
  7.  
  8. Set r2 = Cells(r2.Cells.Value + h + 1, 1)
  9.  
  10. If r2.Offset(1, 0) = "" Then Exit Do
  11.  
  12. Loop
Oct 5 '12 #6
Rabbit
12,516 Expert Mod 8TB
And what problem are you having with the code? Are you getting an error?
Oct 5 '12 #7
I get an error of "Sub or Function not defined", referring to the word "Offset" on line 6. THANKS FOR ANY HELP!
Oct 8 '12 #8
Rabbit
12,516 Expert Mod 8TB
Offset is a method of the range class. You can't use it by itself, it must reference a range object.
So you must use
Expand|Select|Wrap|Line Numbers
  1. Range("A1").Offset(...)
By itself, it is not defined.
Expand|Select|Wrap|Line Numbers
  1. Offset(...)
But I believe the point is moot. You're overcomplicating it, you can accomplish what you want in a single line of code.
Expand|Select|Wrap|Line Numbers
  1. Range("A1:A3").Copy Range("B1")
Oct 8 '12 #9
zmbd
5,501 Expert Mod 4TB
here's from a code I use that enters some 100+ formulas:

'move to the left one cell and continue
ActiveCell.Offset(0, 1).Range("a1").Select
Oct 8 '12 #10
Actually, what I want to do is copy cell A2 to A3; A4 to A5, A6 to A7, etc until there are no more records. And I also want to do the same for column D: copy D2 to D3, D4 to D5, D6 to D7, etc. I was trying to use the Range to have the code progress down column A, doing the copy/paste. Thanks very much for your help. Sorry--I guess I didn't explain it well.
Oct 9 '12 #11
Rabbit
12,516 Expert Mod 8TB
You can do that with minor modifications to the code I posted.
Oct 9 '12 #12

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

Similar topics

2
by: Mrs Howl | last post by:
I don't know if there's even a way to do what I want. I click on a button in an Access form, and it opens an instance of Excel, and opens a workbook and runs a macro that's in it. So far, fine,...
5
by: Mads Petersen | last post by:
Hi, and thanks for previous help. I use following code to export from excel to access. It is executed in excel. I have an excel spreadsheet with one sheet pr. week. this code is therefore...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
3
by: maryam | last post by:
Hi i have some data in excel....I want to perform a series of operations on them and output the results to excel again. I know that some stuff could be used with VBA. however in this special case...
3
by: boaring | last post by:
I need to use Macro's in Excel and always the same changes to 31 Sheets. (31 days in the Month). I'm trying to use a FOR loop but cannot get the correct format to have the sheet number to increment...
1
by: jjGirl | last post by:
All: I'm working on what should be some simple VB code for an Excel macro. For example, I'm replacing "<p>" with a space and using the following snipit of code: RP = ActiveCell.Replace("<p>", "...
0
by: kittu513 | last post by:
Hi I need some help regarding the alignment of the value in the active cell. my code is like this (its VB code to implement an Excel macro) Range("B1").Select ActiveCell.Offset(50,...
3
by: redbenn | last post by:
Hello, I am trying to create an excel macro, that when clicked... a specific cell will match a record in my database, and update certain fields in this record. The Excel file will have a cell...
1
by: sporty9xterra | last post by:
I need help creating a Macro script to return the individual column values in another tab if there is anything listed besides a 0. Can be a negative or positive. I'm just not sure how to create a...
1
by: DataMo | last post by:
I am trying to write an excel macro that reads cells from an excel sheet sequentially (third column) and writes each to a seperate text file with the value in the adjacent cell in column A (user ID)...
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:
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...
0
marktang
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,...
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...

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.