copy data from one column to another on certain condition

cds

Board Regular
Joined
Mar 25, 2012
Messages
84
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]a[/TD]
[TD]b[/TD]
[TD]c[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]batsman[/TD]
[TD] [/TD]
[TD]runs[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD] sunil[/TD]
[TD][/TD]
[TD]14[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD] c kapil b salil[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD] malcom [/TD]
[TD][/TD]
[TD]28[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]runout[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]peter [/TD]
[TD][/TD]
[TD]49[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]b steeve [/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]sachin [/TD]
[TD][/TD]
[TD]35[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]c lily b steev [/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]extra[/TD]
[TD][/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]total[/TD]
[TD][/TD]
[TD]130[/TD]
[/TR]
</tbody>[/TABLE]

Hi, I have data something like aboves

I want help to write vba for copying data in between batsman to extra. Here I want to copy a3 to b2, a5 to b4 & so on whenever c column is blank between batsman & extra . Please help me out


thanks in advance
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How about
Code:
Sub Batsmen()
   Range("C:C").SpecialCells(xlBlanks).Offset(-1, -1).FormulaR1C1 = "=r[1]c[-1]"
   With Intersect(ActiveSheet.UsedRange, Range("B:B"))
      .Value = .Value
'     [COLOR=#0000ff] .SpecialCells(xlConstants).Offset(1, -1).Clear[/COLOR]
'      [COLOR=#ff0000].SpecialCells(xlConstants).Offset(1, -1).EntireRow.Delete[/COLOR]
   End With
End Sub
If you want to remove the data from col A uncomment the line in blue, or if you want to delete the extra rows uncomment the line in red
 
Upvote 0
Thanks for help sir, . I get run time error 1004 "application defined error or objecft defined error. I am using excel 2007. Can you please guide in the process


Thanks once again
 
Upvote 0
Which line of code is highlighted when you get the error?
 
Upvote 0
I get error |run time 1004 - aplication-defined or object-defined error for the following line

Range("C:C").SpecialCells(xlBlanks).Offset(-1, -1).FormulaR1C1 = "=r[1]c[-1]"
 
Upvote 0
Do you have the word Runs in cell C1 as shown in you example?
 
Upvote 0
Another code to test with a copy of your data.
Code:
Sub ScoreCard()
  With Range("B2:B" & Columns("A").Find(What:="Extra", LookAt:=xlWhole, MatchCase:=False).Row - 2)
    .Value = Evaluate(Replace(Replace("if(#="""","""",^)", "#", .Offset(0, 1).Address), "^", .Offset(1, -1).Address))
    .Offset(1, -1).Value = Evaluate(Replace(Replace("if(#="""","""",%)", "#", .Offset(1, 1).Address), "%", .Offset(1, -1).Address))
    .Columns.AutoFit
    .Offset(1, -1).SpecialCells(xlBlanks).EntireRow.Delete
  End With
End Sub
 
Upvote 0
Thank your sir for your time.
Yes, There is word . I modified , it works, but because of word "runs" it is not copying for first player . Probably I have to add row after coulmn word "batting". My new macro is

Sub ColorFruitRedBoldn()


FinalRow = Cells(Rows.Count, 12).End(xlUp).Row
' i = 1
For i = 1 To FinalRow


Range("m:m").SpecialCells(xlBlanks).Offset(1, -1).FormulaR1C1 = "=r[1]c[-1]"
With Intersect(ActiveSheet.UsedRange, Range("B:B"))
.Value = .Value
' .SpecialCells(xlConstants).Offset(1, -1).Clear
' .SpecialCells(xlConstants).Offset(1, -1).EntireRow.Delete
End With

Next i
End Sub


I want run it between batting & Extra only ignore the rows before & after , Plese help me to create loop and add row aftger batting.

thanks
 
Upvote 0
Can you please show an accurate mock-up of your data?
Showing what columns & rows your data is in?
 
Upvote 0
With "Runs" in C1, for layout in post #1 , Fluff's code works for me.

Did you try the other code suggested in post #7 ?
 
Last edited:
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