copy data from one column to another on certain condition

cds

Board Regular
Joined
Mar 25, 2012
Messages
84
abc
1batsman runs
2 sunil14
3 c kapil b salil
4 malcom 28
5runout
6peter 49
7b steeve
8sachin 35
9c lily b steev
10extra4
11total130

<tbody>
</tbody>

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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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