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:
Here is my data. I


1 SRH vs RCB, 2 Hyderabad
3 Sunrisers Hyderabad Innings - 4 207/4
5 Royal Challengers Bangalore 6 Innings - 172
7 Batsmen
8 BattingRunsB4s
David Warner1482
c Mandeep b Aniket Choudhary
Shikhar Dhawan40315
c Sachin Baby b Binny
Moises Henriques52373
c Sachin Baby b Chahal
Yuvraj Singh62277
b Tymal Mills
Deepak Hooda16120
not out
Ben Cutting1660
not out
Extras 7
(b - 0, w - 5, nb - 1, lb - 1)
Total : 207
(20 Ovrs 4 Wkts) RR 10.35
Bowlers
BowlerOMR
Tymal Mills4031
Aniket Choudhary4055
Yuzvendra Chahal4022
Sreenath Aravind3036
Shane Watson3041
Travis Head1011
Stuart Binny1010
FOW
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"

<colgroup><col><col span="3"></colgroup><tbody>
</tbody>
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,215,388
Messages
6,124,659
Members
449,178
Latest member
Emilou

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