Copying Cell Values from One Sheet and Paste based on Condition

madhuchelliah

Board Regular
Joined
Nov 22, 2017
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
Hello Folks, I have dynamic data in A column of sheet 1 and detailed information of those data is available in sheet 2. In sheet 2, C column i have those detailed information. Randomly in C column some cell value is "Total". There will be multiple instance of "Total" in C column. The requirement is i have to copy the data in 1st row of "A" column sheet 1 to the A column of sheet 2 where the 1st instance of "Total" is coming in C column. It has to go on like 2nd row data to 2nd instance, 3rd row data to 3rd instance and so on. see the example below for better understanding. Thank you.

Sheet1

AB
AAAA
BBBB
CCCC
DDDD
EEEE
FFFF


Sheet2

ABC
XXXX
AAAATotal
XXXX
XXXXX
BBBBTotal
XXXXX
CCCCTotal
XXXXX
XXXX
DDDDTotal
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
How about
+Fluff New.xlsm
ABC
1
2 XXXX
3AAAATotal
4 XXXX
5 XXXXX
6BBBBTotal
7 XXXXX
8CCCCTotal
9 XXXXX
10 XXXX
11DDDDTotal
Sheet2
Cell Formulas
RangeFormula
A2:A11A2=IF(C2="total",INDEX(Sheet1!$A$2:$A$7,COUNTIFS(C$2:C2,C2)),"")
 
Upvote 0
He
How about
+Fluff New.xlsm
ABC
1
2 XXXX
3AAAATotal
4 XXXX
5 XXXXX
6BBBBTotal
7 XXXXX
8CCCCTotal
9 XXXXX
10 XXXX
11DDDDTotal
Sheet2
Cell Formulas
RangeFormula
A2:A11A2=IF(C2="total",INDEX(Sheet1!$A$2:$A$7,COUNTIFS(C$2:C2,C2)),"")
Hello Fluff, it is working great. Thanks for your efforts. I forget to mention, that i need the solution in VBA. Sorry for the trouble.
 
Upvote 0
Maybe
VBA Code:
Sub madhuchelliah()
   Dim Cl As Range
   Dim Ary As Variant
   Dim i As Long
   
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   With Sheets("Sheet2")
      .Range("C:C").Replace "Total", "=xxxTotal", xlWhole, , False, , False, False
      For Each Cl In .Range("C:C").SpecialCells(xlFormulas, xlErrors)
         i = i + 1
         Cl.Offset(, -2).Value = Ary(i, 1)
      Next Cl
      .Range("C:C").Replace "=xxxTotal", "Total", xlWhole, , False, , False, False
   End With
End Sub
 
Upvote 0
Solution
Maybe
VBA Code:
Sub madhuchelliah()
   Dim Cl As Range
   Dim Ary As Variant
   Dim i As Long
  
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   With Sheets("Sheet2")
      .Range("C:C").Replace "Total", "=xxxTotal", xlWhole, , False, , False, False
      For Each Cl In .Range("C:C").SpecialCells(xlFormulas, xlErrors)
         i = i + 1
         Cl.Offset(, -2).Value = Ary(i, 1)
      Next Cl
      .Range("C:C").Replace "=xxxTotal", "Total", xlWhole, , False, , False, False
   End With
End Sub
Hello Fluff, it is working great. Thanks for your help.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top