Conditional copy 2 data from different cell
-
QUESTION: i need a macro copy 2 data from different cell in same sheet and paste in different place. example, step 1 macro will copy data if "A1" is "copythis" copy "B1" from "sheet1" and paste in "B2" on "sheet2" step 2 macro will copy data if "A2" is "copythis" copy "B2" from "sheet1" and paste in "B2" on" sheet3" step1 must completed before step2,step2 may not run if "A2" not "copythis" ANSWER: ck, I assume you will run this macro; i.e. You don't want it to be an event macro. Sub copydata() Dim sh1 as worksheet, sh2 as worksheet Dim sh3 as worksheet set sh1 = worksheets("Sheet1") set sh2 = Worksheets("Sheet2") set sh3 = Worksheets("Sheet3") 'Step 1 if sh1.Range("A1").value = "copythis" then sh1.Range("B1").copy sh2.Range("B2") 'Step 2 - not done unless Step 1 is done if sh1.Range("A2").value = "copythis" then sh1.Range("B2").Copy sh3.Range("B2") end if End if End Sub Sorry for the late response - I was sleeping. ---------- FOLLOW-UP ---------- QUESTION: it is okay for me,and sorry for i was made a mistake in question. i need both steps copy and then paste in "same row with moving column" in different sheet. in other words, step 1 macro will copy data if "A1" is "copythis" copy "B1" from "sheet1" and paste in "B2,C2,D2,so on" on "sheet2" step 2 macro will copy data if "A2" is "copythis" copy "B2" from "sheet1" and paste in "B2,C2,D2,so on" on" sheet3"
-
Answer:
ck, Sub copydata() Dim sh1 as worksheet, sh2 as worksheet Dim sh3 as worksheet, i as long set sh1 = worksheets("Sheet1") set sh2 = Worksheets("Sheet2") set sh3 = Worksheets("Sheet3") 'Step 1 if sh1.Range("A1").value = "copythis" then i = sh2.cells(2,sh2.columns.count).End(xltoLeft).column + 1 sh1.Range("B1").copy sh2.cells(2,i) 'Step 2 - not done unless Step 1 is done if sh1.Range("A2").value = "copythis" then i = sh3.cells(2,sh3.columns.count).End(xltoLeft).column + 1 sh1.Range("B2").Copy sh3.Cells(2,i) end if End if End Sub
Miningco.com Visit the source
Related Q & A:
- Where do you buy a cell phone in "The Sims 2?Best solution by Yahoo! Answers
- How to draw cell cycle 2?Best solution by Yahoo! Answers
- Do I need to have a box for my 2 12'' JL audio subs or can they be mounted a different way?Best solution by Yahoo! Answers
- How do you get another copy of W-2?Best solution by Yahoo! Answers
- How much is 1MB of data on a cell phone?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.