Forum Discussion
Copy/Paste Macro using ActiveSheet
Hello
I am trying to do something I think for most would be simple, but I am getting hung up. I want to be able to run a macro that will copy the items in column B 11-21 of the ActiveSheet, and paste them in the same cells on the next sheet If there is a T in column A next to the corresponding B columns row number. I have gotten the macro to work if I am calling out a specific sheet name, and cell. I want it to work with whatever sheet is currently being looked at, and move it to the next sheet. I also copy and pasted code from another website that is not working. I have attached a copy of that code, and an example of my sheet. Any help would be much appreciated. I am still a little new to excel, and have only created a few macros.
See the attached workbook. So that you do not have to worry about malicious code executing upon opening the workbook, this is not a macro-enabled workbook. Instead, I placed the relevant code into the _Code worksheet. But read the information on the _Info worksheet first.
7 Replies
- BrianP475Copper Contributor
Didn't see it add this
- BrianP475Copper Contributor
So I tried to edit the code to include more cells. When I do so I get a method error. So I created 2 more Subs within one module. I get the results I want that way, but I have to run 3 different macros. Is there a punctuation mark used for adding on to the original code? I've tried using a comma, and a semi colon. Ive attached what I was trying to do.
Change
strRange = "B2:B9;B11:B21"
to
strRange = "B2:B9,B11:B21"
(comma instead of semicolon)
- BrianP475Copper Contributor
I messed with it a little the other day, and did what you have posted. I also had to add parenthesis around the argument to get it to work. Now Im researching how to make it so when I transfer to the next sheet it uses the first cell available in that range. So if something is already in cell B2 then it will transfer to the cell below. If not it will go to cell B2. Even if it originated from lets say cell B4 on the previous sheet it will transfer to cell B2 for the next sheet. I do thank you for your help. Im at least able to use this at work now since you gave me the code.
- BrianP475Copper Contributor
Sorry I didn't get back to post a sample. SnowMan gave me exactly what I was asking. There is now way I would have figured that out. Much appreciated for the help. I am going to play with the code a little to add some more rows. Thanks again for all the help.
- SnowMan55Bronze Contributor
See the attached workbook. So that you do not have to worry about malicious code executing upon opening the workbook, this is not a macro-enabled workbook. Instead, I placed the relevant code into the _Code worksheet. But read the information on the _Info worksheet first.
Could you attach a small sample workbook demonstrating the problem (without sensitive data), or if that is not possible, make it available through OneDrive, Google Drive, Dropbox or similar?