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:
[TABLE="width: 341"]
<colgroup><col><col span="3"></colgroup><tbody>[TR]
[TD]Here is my data. I


1 SRH vs RCB, 2 Hyderabad[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"] 3 Sunrisers Hyderabad Innings - 4 207/4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"] 5 Royal Challengers Bangalore 6 Innings - 172[/TD]
[TD][/TD]
[/TR]
[TR]
[TD] 7 Batsmen[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD] 8 Batting[/TD]
[TD]Runs[/TD]
[TD]B[/TD]
[TD]4s[/TD]
[/TR]
[TR]
[TD] David Warner[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="colspan: 2"]c Mandeep b Aniket Choudhary[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Shikhar Dhawan[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]31[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]c Sachin Baby b Binny[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Moises Henriques[/TD]
[TD="align: right"]52[/TD]
[TD="align: right"]37[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]c Sachin Baby b Chahal[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Yuvraj Singh[/TD]
[TD="align: right"]62[/TD]
[TD="align: right"]27[/TD]
[TD="align: right"]7[/TD]
[/TR]
[TR]
[TD]b Tymal Mills[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Deepak Hooda[/TD]
[TD="align: right"]16[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]not out[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Ben Cutting[/TD]
[TD="align: right"]16[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]not out[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Extras 7[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"](b - 0, w - 5, nb - 1, lb - 1)[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Total : 207[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"](20 Ovrs 4 Wkts) RR 10.35[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bowlers[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bowler[/TD]
[TD]O[/TD]
[TD]M[/TD]
[TD]R[/TD]
[/TR]
[TR]
[TD]Tymal Mills[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]31[/TD]
[/TR]
[TR]
[TD]Aniket Choudhary[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]55[/TD]
[/TR]
[TR]
[TD]Yuzvendra Chahal[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]22[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]Sreenath Aravind[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]36[/TD]
[/TR]
[TR]
[TD]Shane Watson[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]41[/TD]
[/TR]
[TR]
[TD]Travis Head[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD]Stuart Binny[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]FOW[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]1-19 (David Warner - 1.4 ovr), 2-93 (Shikhar Dhawan - 10.3 ovr), 3-151 (Moises Henriques - 15.2 ovr), 4-190 (Yuvraj Singh - 18.4 ovr)



Row 8 is heading sort of data. I want data from 9th onwards upto "extra"[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Ok, how about
Code:
Sub Batsmen()
   With Range("C8:C" & Columns(1).find(What:="Extras", LookAt:=xlPart, MatchCase:=False).Row - 1)
   .SpecialCells(xlBlanks).Offset(-1, -1).FormulaR1C1 = "=r[1]c[-1]"
   End With
   With Intersect(ActiveSheet.UsedRange, Range("B:B"))
      .Value = .Value
'      .SpecialCells(xlConstants).Offset(1, -1).Clear
'      .SpecialCells(xlConstants).Offset(1, -1).EntireRow.Delete
   End With
End Sub
 
Upvote 0
@cds
When I 'Reply With Quote' to post #11 and look at your table in WYSIWYG mode,
- 'Runs' is in the second column. If that is the case, then where are we to put the dismissal information? Do we need to create a new column?
- Extras 7 is all in one cell in the first column. Is that actually what you have?

BTW, If there were no Extras in the innings, does the 'Extras' line still always appear in your scorecard?

Since both Fluff & I seem to be somewhat unsure of your exact layout, could you use the link in my signature block below to get one of the HTML Makers and post an accurate screen shot of your sheet? It only needs to go from the first row down to, say, the 'Total: 207' row

Here is what I get when I paste your data into my sheet.

Excel Workbook
ABCD
11 SRH vs RCB, 2 Hyderabad
23 Sunrisers Hyderabad Innings - 4 207/4
35 Royal Challengers Bangalore 6 Innings - 172
47 Batsmen
58 BattingRunsB4s
6David Warner1482
7c Mandeep b Aniket Choudhary
8Shikhar Dhawan40315
9c Sachin Baby b Binny
10Moises Henriques52373
11c Sachin Baby b Chahal
12Yuvraj Singh62277
13b Tymal Mills
14Deepak Hooda16120
15not out
16Ben Cutting1660
17not out
18Extras 7
19(b - 0, w - 5, nb - 1, lb - 1)
20Total : 207
Sample
 
Last edited:
Upvote 0
THanks sir, it is working. THank yo. I have One Question. Sometime my data may not start from row no.8, then how to run the query. Further, after running the above query aI want to delete all rows where c column is blank for the same range i.e from batting to extra only . Can you help me out.


Sir, Thank once again for spending your valuable time to helping me out.
 
Upvote 0
Any chance you could address my questions so that I can continue my interest in the thread too?
 
Upvote 0
Any chance you could address my questions so that I can continue my interest in the thread too?
Yes sir sure, Thank for your time, I will be inserting column b to capture my data before running vba. Furthermore, I want to copy data between batting to extra to another page. For me vba given 'fluff" is working copy data . Now I want dynamically select data between batting & extra rather than c8, How do i do it. Please help me
 
Upvote 0
Yes sir sure, Thank for your time, I will be inserting column b to capture my data before running vba.
That only answers one of my questions. What about the other two?
- Extras 7 is all in one cell in the first column. Is that actually what you have?

BTW, If there were no Extras in the innings, does the 'Extras' line still always appear in your scorecard?


Also ..
I want to copy data between batting to extra to another page
Does the other page already exist? If so,
- What is its name?
- Is there any data already in the 'other' sheet that needs to be kept, or can the code delete it all and start with a clean sheet?
 
Last edited:
Upvote 0
Peter_sss Sir thank you very much . Sorry I didn't see your question.
Extras row start with Extras followed by some numbers say here it is Extras 7 . I have Two sheets per match , first match names 1 & 2 , 3 & 4 for second match. After getting dismissal info i will club all data between batting to Extra to separate sheet with sheet name added in a column in the summary sheet for further analysis .
 
Upvote 0
Peter_sss Sir thank you very much . Sorry I didn't see your question.
Extras row start with Extras followed by some numbers say here it is Extras 7 . I have Two sheets per match , first match names 1 & 2 , 3 & 4 for second match. After getting dismissal info i will club all data between batting to Extra to separate sheet with sheet name added in a column in the summary sheet for further analysis .
That didn't seem to exactly address my questions, but see if this is any use.
It assumes that original data is in the active sheet when the code is run. The code creates a new sheet and puts the results from Batting to Extras (including both those rows) onto that new sheet.

Code:
Sub ScoreCard_v3()
  Dim wsResults As Worksheet
  
  Application.ScreenUpdating = False
  Columns("B").Insert
  With Range("B" & Columns("A").Find(What:="Batting", LookAt:=xlPart, MatchCase:=False).Row + 1 & _
              ":B" & Columns("A").Find(What:="Extra", LookAt:=xlPart, 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))
    .Offset(1, -1).SpecialCells(xlBlanks).EntireRow.Delete
    Sheets.Add After:=ActiveSheet
    Set wsResults = ActiveSheet
    .Offset(-1).Resize(.Rows.Count + 2).EntireRow.Copy Destination:=wsResults.Range("A1")
  End With
  wsResults.UsedRange.Columns.AutoFit
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Dear Peter_SSs , Sir thank you very much indeed it copies to new sheet . If I want to add similar data from multiple sheet to One sheet . How Do I do it, Please guide me. Also advise me any resources available to improve my excel skill.


Thank you once again
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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